Revert 285173 "Removed InProcessBrowserTest::CleanUpOnMainThread()"
[chromium-blink-merge.git] / chrome / browser / extensions / api / webstore / webstore_api.h
blob0410445b59f894e574859c500086fa4a2b2ecb39
1 // Copyright 2014 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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_WEBSTORE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_WEBSTORE_API_H_
8 #include <list>
9 #include <string>
11 #include "base/memory/scoped_ptr.h"
12 #include "base/scoped_observer.h"
13 #include "chrome/browser/extensions/install_observer.h"
14 #include "chrome/common/extensions/api/webstore/webstore_api_constants.h"
15 #include "extensions/browser/browser_context_keyed_api_factory.h"
16 #include "extensions/browser/event_router.h"
18 namespace base {
19 class ListValue;
22 namespace content {
23 class BrowserContext;
26 namespace IPC {
27 class Sender;
30 namespace extensions {
31 class InstallTracker;
33 class WebstoreAPI : public BrowserContextKeyedAPI,
34 public InstallObserver {
35 public:
36 explicit WebstoreAPI(content::BrowserContext* browser_context);
37 virtual ~WebstoreAPI();
39 static WebstoreAPI* Get(content::BrowserContext* browser_context);
41 // Called whenever an inline extension install is started. Examines
42 // |listener_mask| to determine if a download progress or install
43 // stage listener should be added.
44 // |routing_id| refers to the id to which we send any return messages;
45 // |ipc_sender| is the sender through which we send them (typically this
46 // is the TabHelper which started the inline install).
47 void OnInlineInstallStart(int routing_id,
48 IPC::Sender* ipc_sender,
49 const std::string& extension_id,
50 int listener_mask);
52 // Called when an inline extension install finishes. Removes any listeners
53 // related to the |routing_id|-|extension_id| pair.
54 void OnInlineInstallFinished(int routing_id, const std::string& extension_id);
56 // BrowserContextKeyedAPI implementation.
57 static BrowserContextKeyedAPIFactory<WebstoreAPI>* GetFactoryInstance();
59 private:
60 friend class BrowserContextKeyedAPIFactory<WebstoreAPI>;
62 // A simple struct to hold our listeners' information for each observed
63 // install.
64 struct ObservedInstallInfo;
65 typedef std::list<ObservedInstallInfo> ObservedInstallInfoList;
67 // Sends an installation stage update message if we are observing
68 // the extension's install.
69 void SendInstallMessageIfObserved(const std::string& extension_id,
70 api::webstore::InstallStage install_stage);
72 // Removes listeners for the given |extension_id|-|routing_id| pair from
73 // |listeners|.
74 void RemoveListeners(int routing_id,
75 const std::string& extension_id,
76 ObservedInstallInfoList* listeners);
78 // InstallObserver implementation.
79 virtual void OnBeginExtensionDownload(const std::string& extension_id)
80 OVERRIDE;
81 virtual void OnDownloadProgress(const std::string& extension_id,
82 int percent_downloaded) OVERRIDE;
83 virtual void OnBeginCrxInstall(const std::string& extension_id) OVERRIDE;
84 virtual void OnShutdown() OVERRIDE;
86 // BrowserContextKeyedService implementation.
87 virtual void Shutdown() OVERRIDE;
89 // BrowserContextKeyedAPI implementation.
90 static const char* service_name() { return "WebstoreAPI"; }
91 static const bool kServiceIsNULLWhileTesting = true;
93 ObservedInstallInfoList download_progress_listeners_;
94 ObservedInstallInfoList install_stage_listeners_;
95 content::BrowserContext* browser_context_;
96 scoped_ptr<ScopedObserver<InstallTracker, InstallObserver> >
97 install_observer_;
99 DISALLOW_COPY_AND_ASSIGN(WebstoreAPI);
102 } // namespace extensions
104 #endif // CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_WEBSTORE_API_H_