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