/chrome/browser/extensions/api/webstore/webstore_api.h

https://gitlab.com/0072016/Facebook-SDK- · C Header · 104 lines · 60 code · 23 blank · 21 comment · 0 complexity · 2c016d838d16882e8b4b912959bcf4ea MD5 · raw file

  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.
  4. #ifndef CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_WEBSTORE_API_H_
  5. #define CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_WEBSTORE_API_H_
  6. #include <list>
  7. #include <memory>
  8. #include <string>
  9. #include "base/macros.h"
  10. #include "base/scoped_observer.h"
  11. #include "chrome/browser/extensions/install_observer.h"
  12. #include "chrome/common/extensions/api/webstore/webstore_api_constants.h"
  13. #include "extensions/browser/browser_context_keyed_api_factory.h"
  14. #include "extensions/browser/event_router.h"
  15. namespace base {
  16. class ListValue;
  17. }
  18. namespace content {
  19. class BrowserContext;
  20. }
  21. namespace IPC {
  22. class Sender;
  23. }
  24. namespace extensions {
  25. class InstallTracker;
  26. class WebstoreAPI : public BrowserContextKeyedAPI,
  27. public InstallObserver {
  28. public:
  29. explicit WebstoreAPI(content::BrowserContext* browser_context);
  30. ~WebstoreAPI() override;
  31. static WebstoreAPI* Get(content::BrowserContext* browser_context);
  32. // Called whenever an inline extension install is started. Examines
  33. // |listener_mask| to determine if a download progress or install
  34. // stage listener should be added.
  35. // |routing_id| refers to the id to which we send any return messages;
  36. // |ipc_sender| is the sender through which we send them (typically this
  37. // is the TabHelper which started the inline install).
  38. void OnInlineInstallStart(int routing_id,
  39. IPC::Sender* ipc_sender,
  40. const std::string& extension_id,
  41. int listener_mask);
  42. // Called when an inline extension install finishes. Removes any listeners
  43. // related to the |routing_id|-|extension_id| pair.
  44. void OnInlineInstallFinished(int routing_id, const std::string& extension_id);
  45. // BrowserContextKeyedAPI implementation.
  46. static BrowserContextKeyedAPIFactory<WebstoreAPI>* GetFactoryInstance();
  47. private:
  48. friend class BrowserContextKeyedAPIFactory<WebstoreAPI>;
  49. // A simple struct to hold our listeners' information for each observed
  50. // install.
  51. struct ObservedInstallInfo;
  52. typedef std::list<ObservedInstallInfo> ObservedInstallInfoList;
  53. // Sends an installation stage update message if we are observing
  54. // the extension's install.
  55. void SendInstallMessageIfObserved(const std::string& extension_id,
  56. api::webstore::InstallStage install_stage);
  57. // Removes listeners for the given |extension_id|-|routing_id| pair from
  58. // |listeners|.
  59. void RemoveListeners(int routing_id,
  60. const std::string& extension_id,
  61. ObservedInstallInfoList* listeners);
  62. // InstallObserver implementation.
  63. void OnBeginExtensionDownload(const std::string& extension_id) override;
  64. void OnDownloadProgress(const std::string& extension_id,
  65. int percent_downloaded) override;
  66. void OnBeginCrxInstall(const std::string& extension_id) override;
  67. void OnShutdown() override;
  68. // BrowserContextKeyedService implementation.
  69. void Shutdown() override;
  70. // BrowserContextKeyedAPI implementation.
  71. static const char* service_name() { return "WebstoreAPI"; }
  72. static const bool kServiceIsNULLWhileTesting = true;
  73. ObservedInstallInfoList download_progress_listeners_;
  74. ObservedInstallInfoList install_stage_listeners_;
  75. content::BrowserContext* browser_context_;
  76. std::unique_ptr<ScopedObserver<InstallTracker, InstallObserver>>
  77. install_observer_;
  78. DISALLOW_COPY_AND_ASSIGN(WebstoreAPI);
  79. };
  80. } // namespace extensions
  81. #endif // CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_WEBSTORE_API_H_