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