Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTERNAL_EXTENSION_LOADER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTERNAL_LOADER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTERNAL_EXTENSION_LOADER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTERNAL_LOADER_H_ |
| 7 | 7 |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 | 11 |
| 12 class ExternalExtensionProviderImpl; | |
| 13 | 12 |
|
Joao da Silva
2012/07/16 08:08:47
Nit: remove extra newline
Devlin
2012/07/16 15:40:30
Done.
| |
| 14 namespace base { | 13 namespace base { |
| 15 class DictionaryValue; | 14 class DictionaryValue; |
| 16 } | 15 } |
| 17 | 16 |
| 17 namespace extensions { | |
| 18 class ExternalProviderImpl; | |
| 19 | |
| 18 // Base class for gathering a list of external extensions. Subclasses | 20 // Base class for gathering a list of external extensions. Subclasses |
| 19 // implement loading from registry, JSON file, policy. | 21 // implement loading from registry, JSON file, policy. |
| 20 // Instances are owned by ExternalExtensionProviderImpl objects. | 22 // Instances are owned by ExternalProviderImpl objects. |
| 21 // Instances are created on the UI thread and expect public method calls from | 23 // Instances are created on the UI thread and expect public method calls from |
| 22 // the UI thread. Some subclasses introduce new methods that are executed on the | 24 // the UI thread. Some subclasses introduce new methods that are executed on the |
| 23 // FILE thread. | 25 // FILE thread. |
| 24 // The sequence of loading the extension list: | 26 // The sequence of loading the extension list: |
| 25 // 1.) StartLoading() - checks if a loading task is already running | 27 // 1.) StartLoading() - checks if a loading task is already running |
| 26 // 2.) Load() - implemented in subclasses | 28 // 2.) Load() - implemented in subclasses |
| 27 // 3.) LoadFinished() | 29 // 3.) LoadFinished() |
| 28 // 4.) owner_->SetPrefs() | 30 // 4.) owner_->SetPrefs() |
| 29 class ExternalExtensionLoader | 31 class ExternalLoader : public base::RefCountedThreadSafe<ExternalLoader> { |
| 30 : public base::RefCountedThreadSafe<ExternalExtensionLoader> { | |
| 31 public: | 32 public: |
| 32 explicit ExternalExtensionLoader(); | 33 explicit ExternalLoader(); |
|
Joao da Silva
2012/07/16 08:08:47
Nit: this doesn't have to be explicit
Devlin
2012/07/16 15:40:30
Done.
| |
| 33 | 34 |
| 34 // Specifies the provider that owns this object. | 35 // Specifies the provider that owns this object. |
| 35 void Init(ExternalExtensionProviderImpl* owner); | 36 void Init(ExternalProviderImpl* owner); |
| 36 | 37 |
| 37 // Called by the owner before it gets deleted. | 38 // Called by the owner before it gets deleted. |
| 38 void OwnerShutdown(); | 39 void OwnerShutdown(); |
| 39 | 40 |
| 40 // Initiates the possibly asynchronous loading of extension list. | 41 // Initiates the possibly asynchronous loading of extension list. |
| 41 // It is the responsibility of the caller to ensure that calls to | 42 // It is the responsibility of the caller to ensure that calls to |
| 42 // this method do not overlap with each other. | 43 // this method do not overlap with each other. |
| 43 // Implementations of this method should save the loaded results | 44 // Implementations of this method should save the loaded results |
| 44 // in prefs_ and then call LoadFinished. | 45 // in prefs_ and then call LoadFinished. |
| 45 virtual void StartLoading() = 0; | 46 virtual void StartLoading() = 0; |
| 46 | 47 |
| 47 // Some external providers allow relative file paths to local CRX files. | 48 // Some external providers allow relative file paths to local CRX files. |
| 48 // Subclasses that want this behavior should override this method to | 49 // Subclasses that want this behavior should override this method to |
| 49 // return the absolute path from which relative paths should be resolved. | 50 // return the absolute path from which relative paths should be resolved. |
| 50 // By default, return an empty path, which indicates that relative paths | 51 // By default, return an empty path, which indicates that relative paths |
| 51 // are not allowed. | 52 // are not allowed. |
| 52 virtual const FilePath GetBaseCrxFilePath(); | 53 virtual const FilePath GetBaseCrxFilePath(); |
| 53 | 54 |
| 54 protected: | 55 protected: |
| 55 virtual ~ExternalExtensionLoader(); | 56 virtual ~ExternalLoader(); |
| 56 | 57 |
| 57 // Notifies the provider that the list of extensions has been loaded. | 58 // Notifies the provider that the list of extensions has been loaded. |
| 58 void LoadFinished(); | 59 void LoadFinished(); |
| 59 | 60 |
| 60 // Used for passing the list of extensions from the method that loads them | 61 // Used for passing the list of extensions from the method that loads them |
| 61 // to |LoadFinished|. To ensure thread safety, the rules are the following: | 62 // to |LoadFinished|. To ensure thread safety, the rules are the following: |
| 62 // if this value is written on another thread than the UI, then it should | 63 // if this value is written on another thread than the UI, then it should |
| 63 // only be written in a task that was posted from |StartLoading|. After that, | 64 // only be written in a task that was posted from |StartLoading|. After that, |
| 64 // this task should invoke |LoadFinished| with a PostTask. This scheme of | 65 // this task should invoke |LoadFinished| with a PostTask. This scheme of |
| 65 // posting tasks will avoid concurrent access and imply the necessary memory | 66 // posting tasks will avoid concurrent access and imply the necessary memory |
| 66 // barriers. | 67 // barriers. |
| 67 scoped_ptr<base::DictionaryValue> prefs_; | 68 scoped_ptr<base::DictionaryValue> prefs_; |
| 68 | 69 |
| 69 private: | 70 private: |
| 70 friend class base::RefCountedThreadSafe<ExternalExtensionLoader>; | 71 friend class base::RefCountedThreadSafe<ExternalLoader>; |
| 71 | 72 |
| 72 ExternalExtensionProviderImpl* owner_; // weak | 73 ExternalProviderImpl* owner_; // weak |
| 73 | 74 |
| 74 // Set to true if loading the extensions is already running. New requests | 75 // Set to true if loading the extensions is already running. New requests |
| 75 // are ignored while this is set true. | 76 // are ignored while this is set true. |
| 76 bool running_; | 77 bool running_; |
| 77 | 78 |
| 78 DISALLOW_COPY_AND_ASSIGN(ExternalExtensionLoader); | 79 DISALLOW_COPY_AND_ASSIGN(ExternalLoader); |
| 79 }; | 80 }; |
| 80 | 81 |
| 81 #endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_EXTENSION_LOADER_H_ | 82 } // namespace extensions |
| 83 | |
| 84 #endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_LOADER_H_ | |
| OLD | NEW |