OLD | NEW |
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 #include "chrome/browser/extensions/api/copresence/copresence_api.h" | 5 #include "chrome/browser/extensions/api/copresence/copresence_api.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/memory/linked_ptr.h" | 8 #include "base/memory/linked_ptr.h" |
9 #include "chrome/browser/copresence/chrome_whispernet_client.h" | 9 #include "chrome/browser/copresence/chrome_whispernet_client.h" |
10 #include "chrome/common/chrome_version_info.h" | 10 #include "chrome/common/chrome_version_info.h" |
11 #include "chrome/common/extensions/api/copresence.h" | 11 #include "chrome/common/extensions/api/copresence.h" |
12 #include "components/copresence/proto/data.pb.h" | 12 #include "components/copresence/proto/data.pb.h" |
13 #include "components/copresence/proto/enums.pb.h" | 13 #include "components/copresence/proto/enums.pb.h" |
14 #include "components/copresence/proto/rpcs.pb.h" | 14 #include "components/copresence/proto/rpcs.pb.h" |
15 #include "components/copresence/public/copresence_manager.h" | 15 #include "components/copresence/public/copresence_manager.h" |
16 #include "components/copresence/public/whispernet_client.h" | 16 #include "components/copresence/public/whispernet_client.h" |
17 #include "content/public/browser/browser_context.h" | 17 #include "content/public/browser/browser_context.h" |
18 #include "extensions/browser/event_router.h" | 18 #include "extensions/browser/event_router.h" |
19 | 19 |
20 namespace extensions { | 20 namespace extensions { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 base::LazyInstance<BrowserContextKeyedAPIFactory<CopresenceService> > | 24 base::LazyInstance<BrowserContextKeyedAPIFactory<CopresenceService>> |
25 g_factory = LAZY_INSTANCE_INITIALIZER; | 25 g_factory = LAZY_INSTANCE_INITIALIZER; |
26 | 26 |
27 const char kInvalidOperationsMessage[] = | 27 const char kInvalidOperationsMessage[] = |
28 "Invalid operation in operations array."; | 28 "Invalid operation in operations array."; |
29 const char kShuttingDownMessage[] = "Shutting down."; | 29 const char kShuttingDownMessage[] = "Shutting down."; |
30 | 30 |
31 } // namespace | 31 } // namespace |
32 | 32 |
33 // CopresenceService implementation: | 33 // CopresenceService implementation: |
34 | 34 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 // with subscriptions, use that instead of the apps_by_subs registry. | 74 // with subscriptions, use that instead of the apps_by_subs registry. |
75 std::string app_id = apps_by_subscription_id_[subscription_id]; | 75 std::string app_id = apps_by_subscription_id_[subscription_id]; |
76 | 76 |
77 if (app_id.empty()) { | 77 if (app_id.empty()) { |
78 LOG(ERROR) << "Skipping message from unrecognized subscription " | 78 LOG(ERROR) << "Skipping message from unrecognized subscription " |
79 << subscription_id; | 79 << subscription_id; |
80 return; | 80 return; |
81 } | 81 } |
82 | 82 |
83 int message_count = messages.size(); | 83 int message_count = messages.size(); |
84 std::vector<linked_ptr<api::copresence::Message> > api_messages( | 84 std::vector<linked_ptr<api::copresence::Message>> api_messages( |
85 message_count); | 85 message_count); |
86 | 86 |
87 for (int m = 0; m < message_count; ++m) { | 87 for (int m = 0; m < message_count; ++m) { |
88 api_messages[m].reset(new api::copresence::Message); | 88 api_messages[m].reset(new api::copresence::Message); |
89 api_messages[m]->type = messages[m].type().type(); | 89 api_messages[m]->type = messages[m].type().type(); |
90 api_messages[m]->payload = messages[m].payload(); | 90 api_messages[m]->payload = messages[m].payload(); |
91 DVLOG(2) << "Dispatching message of type " << api_messages[m]->type << ":\n" | 91 DVLOG(2) << "Dispatching message of type " << api_messages[m]->type << ":\n" |
92 << api_messages[m]->payload; | 92 << api_messages[m]->payload; |
93 } | 93 } |
94 | 94 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 api::copresence::SetApiKey::Params::Create(*args_)); | 170 api::copresence::SetApiKey::Params::Create(*args_)); |
171 EXTENSION_FUNCTION_VALIDATE(params.get()); | 171 EXTENSION_FUNCTION_VALIDATE(params.get()); |
172 | 172 |
173 // The api key may be set to empty, to clear it. | 173 // The api key may be set to empty, to clear it. |
174 CopresenceService::GetFactoryInstance()->Get(browser_context()) | 174 CopresenceService::GetFactoryInstance()->Get(browser_context()) |
175 ->set_api_key(params->api_key); | 175 ->set_api_key(params->api_key); |
176 return RespondNow(NoArguments()); | 176 return RespondNow(NoArguments()); |
177 } | 177 } |
178 | 178 |
179 } // namespace extensions | 179 } // namespace extensions |
OLD | NEW |