OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2006-2008 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_EXTENSIONS_SERVICE_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/file_path.h" |
| 11 #include "base/message_loop.h" |
| 12 #include "base/ref_counted.h" |
| 13 #include "base/task.h" |
| 14 #include "chrome/browser/extensions/extension.h" |
| 15 |
| 16 typedef std::vector<Extension*> ExtensionList; |
| 17 class ExtensionsServiceBackend; |
| 18 |
| 19 // Interface for the frontend to implement. Typically, this will be |
| 20 // ExtensionsService, but it can also be a test harness. |
| 21 class ExtensionsServiceFrontendInterface |
| 22 : public base::RefCountedThreadSafe<ExtensionsServiceFrontendInterface> { |
| 23 public: |
| 24 virtual ~ExtensionsServiceFrontendInterface(){} |
| 25 |
| 26 // The message loop to invoke the frontend's methods on. |
| 27 virtual MessageLoop* GetMessageLoop() = 0; |
| 28 |
| 29 // Called when loading an extension fails. |
| 30 virtual void OnExtensionLoadError(const std::wstring& message) = 0; |
| 31 |
| 32 // Called with results from LoadExtensionsFromDirectory(). The frontend |
| 33 // takes ownership of the list. |
| 34 virtual void OnExtensionsLoadedFromDirectory(ExtensionList* extensions) = 0; |
| 35 }; |
| 36 |
| 37 |
| 38 // Manages installed and running Chromium extensions. |
| 39 class ExtensionsService : public ExtensionsServiceFrontendInterface { |
| 40 public: |
| 41 ExtensionsService(const FilePath& profile_directory); |
| 42 ~ExtensionsService(); |
| 43 |
| 44 // Gets the list of currently installed extensions. |
| 45 const ExtensionList* extensions() const { |
| 46 return &extensions_; |
| 47 } |
| 48 |
| 49 // Initialize and start all installed extensions. |
| 50 bool Init(); |
| 51 |
| 52 // ExtensionsServiceFrontendInterface |
| 53 virtual MessageLoop* GetMessageLoop(); |
| 54 virtual void OnExtensionLoadError(const std::wstring& message); |
| 55 virtual void OnExtensionsLoadedFromDirectory(ExtensionList* extensions); |
| 56 |
| 57 private: |
| 58 // The name of the directory inside the profile where extensions are |
| 59 // installed to. |
| 60 static const FilePath::CharType* kInstallDirectoryName; |
| 61 |
| 62 // The message loop for the thread the ExtensionsService is running on. |
| 63 MessageLoop* message_loop_; |
| 64 |
| 65 // The backend that will do IO on behalf of this instance. |
| 66 scoped_refptr<ExtensionsServiceBackend> backend_; |
| 67 |
| 68 // The current list of installed extensions. |
| 69 ExtensionList extensions_; |
| 70 |
| 71 // The full path to the directory where extensions are installed. |
| 72 FilePath install_directory_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(ExtensionsService); |
| 75 }; |
| 76 |
| 77 // Implements IO for the ExtensionsService. |
| 78 // TODO(aa): Extract an interface out of this for testing the frontend, once the |
| 79 // frontend has significant logic to test. |
| 80 class ExtensionsServiceBackend |
| 81 : public base::RefCountedThreadSafe<ExtensionsServiceBackend> { |
| 82 public: |
| 83 ExtensionsServiceBackend(){}; |
| 84 |
| 85 // Loads extensions from a directory. The extensions are assumed to be |
| 86 // unpacked in directories that are direct children of the specified path. |
| 87 // Errors are reported through OnExtensionLoadError(). On completion, |
| 88 // OnExtensionsLoadedFromDirectory() is called with any successfully loaded |
| 89 // extensions. |
| 90 bool LoadExtensionsFromDirectory( |
| 91 const FilePath &path, |
| 92 scoped_refptr<ExtensionsServiceFrontendInterface> frontend); |
| 93 |
| 94 private: |
| 95 // Notify a frontend that there was an error loading an extension. |
| 96 void ReportExtensionLoadError(ExtensionsServiceFrontendInterface* frontend, |
| 97 const std::wstring& error); |
| 98 |
| 99 // Notify a frontend that extensions were loaded. |
| 100 void ReportExtensionsLoaded(ExtensionsServiceFrontendInterface* frontend, |
| 101 ExtensionList* extensions); |
| 102 |
| 103 DISALLOW_COPY_AND_ASSIGN(ExtensionsServiceBackend); |
| 104 }; |
| 105 |
| 106 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ |
OLD | NEW |