Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Side by Side Diff: chrome/browser/extensions/api/copresence/copresence_api.h

Issue 441103002: Tests for the Copresence API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@api
Patch Set: Rewrite Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "chrome/browser/extensions/api/copresence/copresence_translations.h" 14 #include "chrome/browser/extensions/api/copresence/copresence_translations.h"
15 #include "chrome/browser/extensions/chrome_extension_function.h" 15 #include "chrome/browser/extensions/chrome_extension_function.h"
16 #include "chrome/common/extensions/api/copresence.h" 16 #include "chrome/common/extensions/api/copresence.h"
17 #include "components/copresence/public/copresence_client_delegate.h" 17 #include "components/copresence/public/copresence_manager_delegate.h"
18 #include "extensions/browser/browser_context_keyed_api_factory.h" 18 #include "extensions/browser/browser_context_keyed_api_factory.h"
19 19
20 namespace copresence { 20 namespace copresence {
21 class CopresenceClient; 21 class CopresenceManager;
22 class WhispernetClient; 22 class WhispernetClient;
23 } 23 }
24 24
25 namespace extensions { 25 namespace extensions {
26 26
27 class CopresenceService : public BrowserContextKeyedAPI, 27 class CopresenceService : public BrowserContextKeyedAPI,
28 public copresence::CopresenceClientDelegate { 28 public copresence::CopresenceManagerDelegate {
29 public: 29 public:
30 explicit CopresenceService(content::BrowserContext* context); 30 explicit CopresenceService(content::BrowserContext* context);
31 virtual ~CopresenceService(); 31 virtual ~CopresenceService();
32 32
33 // BrowserContextKeyedAPI implementation. 33 // BrowserContextKeyedAPI implementation.
34 virtual void Shutdown() OVERRIDE; 34 virtual void Shutdown() OVERRIDE;
35 35
36 // These accessors will always return an object. If the object doesn't exist, 36 // These accessors will always return an object (except during shutdown).
37 // they will create one first. 37 // If the object doesn't exist, they will create one first.
38 copresence::CopresenceClient* client(); 38 copresence::CopresenceManager* manager();
39 copresence::WhispernetClient* whispernet_client(); 39 copresence::WhispernetClient* whispernet_client();
40 40
41 // A registry containing the app id's associated with every subscription. 41 // A registry containing the app id's associated with every subscription.
42 SubscriptionToAppMap& apps_by_subscription_id() { 42 SubscriptionToAppMap& apps_by_subscription_id() {
43 return apps_by_subscription_id_; 43 return apps_by_subscription_id_;
44 } 44 }
45 45
46 void set_api_key(const std::string& api_key) { api_key_ = api_key; } 46 void set_api_key(const std::string& api_key) { api_key_ = api_key; }
47 47
48 // Manager override for testing.
49 void set_manager_for_testing(
50 scoped_ptr<copresence::CopresenceManager> manager);
51
48 // BrowserContextKeyedAPI implementation. 52 // BrowserContextKeyedAPI implementation.
49 static BrowserContextKeyedAPIFactory<CopresenceService>* GetFactoryInstance(); 53 static BrowserContextKeyedAPIFactory<CopresenceService>* GetFactoryInstance();
50 54
51 private: 55 private:
52 friend class BrowserContextKeyedAPIFactory<CopresenceService>; 56 friend class BrowserContextKeyedAPIFactory<CopresenceService>;
53 57
54 // CopresenceClientDelegate overrides: 58 // CopresenceManagerDelegate implementation
55 virtual void HandleMessages( 59 virtual void HandleMessages(
56 const std::string& app_id, 60 const std::string& app_id,
57 const std::string& subscription_id, 61 const std::string& subscription_id,
58 const std::vector<copresence::Message>& message) OVERRIDE; 62 const std::vector<copresence::Message>& message) OVERRIDE;
59 virtual net::URLRequestContextGetter* GetRequestContext() const OVERRIDE; 63 virtual net::URLRequestContextGetter* GetRequestContext() const OVERRIDE;
60 virtual const std::string GetPlatformVersionString() const OVERRIDE; 64 virtual const std::string GetPlatformVersionString() const OVERRIDE;
61 virtual const std::string GetAPIKey() const OVERRIDE; 65 virtual const std::string GetAPIKey() const OVERRIDE;
62 virtual copresence::WhispernetClient* GetWhispernetClient() OVERRIDE; 66 virtual copresence::WhispernetClient* GetWhispernetClient() OVERRIDE;
63 67
64 // BrowserContextKeyedAPI implementation. 68 // BrowserContextKeyedAPI implementation.
65 static const char* service_name() { return "CopresenceService"; } 69 static const char* service_name() { return "CopresenceService"; }
66 70
67 bool is_shutting_down_; 71 bool is_shutting_down_;
68 std::map<std::string, std::string> apps_by_subscription_id_; 72 std::map<std::string, std::string> apps_by_subscription_id_;
69 73
70 content::BrowserContext* const browser_context_; 74 content::BrowserContext* const browser_context_;
71 std::string api_key_; 75 std::string api_key_;
72 76
73 scoped_ptr<copresence::CopresenceClient> client_; 77 scoped_ptr<copresence::CopresenceManager> manager_;
74 scoped_ptr<copresence::WhispernetClient> whispernet_client_; 78 scoped_ptr<copresence::WhispernetClient> whispernet_client_;
75 79
76 DISALLOW_COPY_AND_ASSIGN(CopresenceService); 80 DISALLOW_COPY_AND_ASSIGN(CopresenceService);
77 }; 81 };
78 82
79 template <> 83 template <>
80 void BrowserContextKeyedAPIFactory< 84 void BrowserContextKeyedAPIFactory<
81 CopresenceService>::DeclareFactoryDependencies(); 85 CopresenceService>::DeclareFactoryDependencies();
82 86
83 class CopresenceExecuteFunction : public ChromeUIThreadExtensionFunction { 87 class CopresenceExecuteFunction : public ChromeUIThreadExtensionFunction {
(...skipping 13 matching lines...) Expand all
97 DECLARE_EXTENSION_FUNCTION("copresence.setApiKey", COPRESENCE_SETAPIKEY); 101 DECLARE_EXTENSION_FUNCTION("copresence.setApiKey", COPRESENCE_SETAPIKEY);
98 102
99 protected: 103 protected:
100 virtual ~CopresenceSetApiKeyFunction() {} 104 virtual ~CopresenceSetApiKeyFunction() {}
101 virtual ExtensionFunction::ResponseAction Run() OVERRIDE; 105 virtual ExtensionFunction::ResponseAction Run() OVERRIDE;
102 }; 106 };
103 107
104 } // namespace extensions 108 } // namespace extensions
105 109
106 #endif // CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_ 110 #endif // CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698