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_
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"
30 namespace extensions
{
33 class WebstoreAPI
: public BrowserContextKeyedAPI
,
34 public InstallObserver
{
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
,
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();
60 friend class BrowserContextKeyedAPIFactory
<WebstoreAPI
>;
62 // A simple struct to hold our listeners' information for each observed
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
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
)
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
> >
99 DISALLOW_COPY_AND_ASSIGN(WebstoreAPI
);
102 } // namespace extensions
104 #endif // CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_WEBSTORE_API_H_