• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTERNAL_PREF_EXTENSION_LOADER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTERNAL_PREF_EXTENSION_LOADER_H_
7 #pragma once
8 
9 #include "chrome/browser/extensions/external_extension_loader.h"
10 
11 #include <string>
12 
13 #include "base/memory/scoped_ptr.h"
14 #include "base/values.h"
15 
16 // A specialization of the ExternalExtensionLoader that uses a json file to
17 // look up which external extensions are registered.
18 // Instances of this class are expected to be created and destroyed on the UI
19 // thread and they are expecting public method calls from the UI thread.
20 class ExternalPrefExtensionLoader : public ExternalExtensionLoader {
21  public:
22   // |base_path_key| is the directory containing the external_extensions.json
23   // file.  Relative file paths to extension files are resolved relative
24   // to this path.
25   explicit ExternalPrefExtensionLoader(int base_path_key);
26 
27   virtual const FilePath GetBaseCrxFilePath();
28 
29  protected:
30   virtual void StartLoading();
31 
32  private:
33   friend class base::RefCountedThreadSafe<ExternalExtensionLoader>;
34 
~ExternalPrefExtensionLoader()35   virtual ~ExternalPrefExtensionLoader() {}
36 
37   void LoadOnFileThread();
38 
39   int base_path_key_;
40   FilePath base_path_;
41 
42   DISALLOW_COPY_AND_ASSIGN(ExternalPrefExtensionLoader);
43 };
44 
45 // A simplified version of ExternalPrefExtensionLoader that loads the dictionary
46 // from json data specified in a string.
47 class ExternalTestingExtensionLoader : public ExternalExtensionLoader {
48  public:
49   ExternalTestingExtensionLoader(
50       const std::string& json_data,
51       const FilePath& fake_base_path);
52 
53   virtual const FilePath GetBaseCrxFilePath();
54 
55  protected:
56   virtual void StartLoading();
57 
58  private:
59   friend class base::RefCountedThreadSafe<ExternalExtensionLoader>;
60 
61   virtual ~ExternalTestingExtensionLoader();
62 
63   FilePath fake_base_path_;
64   scoped_ptr<DictionaryValue> testing_prefs_;
65 
66   DISALLOW_COPY_AND_ASSIGN(ExternalTestingExtensionLoader);
67 };
68 
69 #endif  // CHROME_BROWSER_EXTENSIONS_EXTERNAL_PREF_EXTENSION_LOADER_H_
70