Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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_EXTENSION_LOADER_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTERNAL_EXTENSION_LOADER_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "base/lock.h" | |
| 10 #include "base/ref_counted.h" | |
| 11 #include "base/scoped_ptr.h" | |
| 12 | |
| 13 class DictionaryValue; | |
| 14 class ExternalExtensionProviderImpl; | |
| 15 | |
| 16 // Base class for gathering a list of external extensions. Subclasses | |
| 17 // implement loading from registry, JSON file, policy. | |
| 18 // Instances are owned by ExternalExtensionProviderImpl objects. | |
| 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 | |
| 21 // FILE thread. | |
| 22 // The sequence of loading the extension list: | |
| 23 // 1.) StartLoading() - checks if a loading task is already running | |
| 24 // 2.) Load() - implemented in subclasses | |
| 25 // 3.) FinishLoading() | |
| 26 // 4.) owner_->SetPrefs() | |
| 27 class ExternalExtensionLoader | |
| 28 : public base::RefCountedThreadSafe<ExternalExtensionLoader> { | |
| 29 public: | |
| 30 explicit ExternalExtensionLoader() : running_(false) {} | |
| 31 | |
| 32 // Specifies the provider that owns this object. | |
| 33 void Init(ExternalExtensionProviderImpl* owner); | |
| 34 | |
| 35 // Called by the owner before it gets deleted. | |
| 36 void OwnerShutdown(); | |
| 37 | |
| 38 // Initiates the possibly asynchronous loading of extension list. | |
| 39 void StartLoading(); | |
| 40 | |
| 41 protected: | |
| 42 virtual ~ExternalExtensionLoader() {} | |
| 43 | |
| 44 // Notifies the provider that the list of extensions has been loaded. | |
| 45 void LoadFinished(); | |
| 46 | |
| 47 // The external-source specific logic that loads the list of extensions. | |
| 48 virtual void Load() = 0; | |
| 49 | |
| 50 // Protects |prefs_|. | |
| 51 Lock lock_; | |
|
Aaron Boodman
2011/01/06 18:54:40
It is rare to use Locks directly in Chromium code
gfeher
2011/01/07 00:10:01
Done.
| |
| 52 | |
| 53 // Used for passing the list of extensions from the method that loads them | |
| 54 // to |LoadFinished|. Depending on the implementation of |Load|, this | |
| 55 // may be accessed from multiple threads. | |
| 56 scoped_ptr<DictionaryValue> prefs_; | |
| 57 | |
| 58 private: | |
| 59 friend class base::RefCountedThreadSafe<ExternalExtensionLoader>; | |
| 60 | |
| 61 ExternalExtensionProviderImpl* owner_; // weak | |
| 62 | |
| 63 // Set to true if loading the extensions is already running. New requests | |
| 64 // are ignored while this is set true. | |
| 65 bool running_; | |
| 66 | |
| 67 DISALLOW_COPY_AND_ASSIGN(ExternalExtensionLoader); | |
| 68 }; | |
| 69 | |
| 70 #endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_EXTENSION_LOADER_H_ | |
| OLD | NEW |