| 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" | 
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  108       new Event(api::copresence::OnMessagesReceived::kEventName, |  108       new Event(api::copresence::OnMessagesReceived::kEventName, | 
|  109                 api::copresence::OnMessagesReceived::Create(subscription_id, |  109                 api::copresence::OnMessagesReceived::Create(subscription_id, | 
|  110                                                             api_messages), |  110                                                             api_messages), | 
|  111                 browser_context_)); |  111                 browser_context_)); | 
|  112   EventRouter::Get(browser_context_) |  112   EventRouter::Get(browser_context_) | 
|  113       ->DispatchEventToExtension(app_id, event.Pass()); |  113       ->DispatchEventToExtension(app_id, event.Pass()); | 
|  114   DVLOG(2) << "Passed " << api_messages.size() << " messages to app \"" |  114   DVLOG(2) << "Passed " << api_messages.size() << " messages to app \"" | 
|  115            << app_id << "\" for subscription \"" << subscription_id << "\""; |  115            << app_id << "\" for subscription \"" << subscription_id << "\""; | 
|  116 } |  116 } | 
|  117  |  117  | 
 |  118 void CopresenceService::HandleStatusUpdate( | 
 |  119     copresence::CopresenceStatus status) { | 
 |  120   // Update all apps using copresence with the new status update. | 
 |  121   for (const std::string& app_id : copresence_apps_) { | 
 |  122     scoped_ptr<Event> event( | 
 |  123         new Event(api::copresence::OnStatusUpdated::kEventName, | 
 |  124                   api::copresence::OnStatusUpdated::Create( | 
 |  125                       api::copresence::STATUS_AUDIOFAILED), | 
 |  126                   browser_context_)); | 
 |  127     EventRouter::Get(browser_context_) | 
 |  128         ->DispatchEventToExtension(app_id, event.Pass()); | 
 |  129     DVLOG(2) << "Sent Audio Failed status update to app_id: " << app_id; | 
 |  130   } | 
 |  131 } | 
 |  132  | 
|  118 net::URLRequestContextGetter* CopresenceService::GetRequestContext() const { |  133 net::URLRequestContextGetter* CopresenceService::GetRequestContext() const { | 
|  119   return browser_context_->GetRequestContext(); |  134   return browser_context_->GetRequestContext(); | 
|  120 } |  135 } | 
|  121  |  136  | 
|  122 const std::string CopresenceService::GetPlatformVersionString() const { |  137 const std::string CopresenceService::GetPlatformVersionString() const { | 
|  123   return chrome::VersionInfo().CreateVersionString(); |  138   return chrome::VersionInfo().CreateVersionString(); | 
|  124 } |  139 } | 
|  125  |  140  | 
|  126 const std::string CopresenceService::GetAPIKey(const std::string& app_id) |  141 const std::string CopresenceService::GetAPIKey(const std::string& app_id) | 
|  127     const { |  142     const { | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  160  |  175  | 
|  161   // Each execute will correspond to one ReportRequest protocol buffer. |  176   // Each execute will correspond to one ReportRequest protocol buffer. | 
|  162   copresence::ReportRequest request; |  177   copresence::ReportRequest request; | 
|  163   if (!PrepareReportRequestProto(params->operations, |  178   if (!PrepareReportRequestProto(params->operations, | 
|  164                                  extension_id(), |  179                                  extension_id(), | 
|  165                                  &service->apps_by_subscription_id(), |  180                                  &service->apps_by_subscription_id(), | 
|  166                                  &request)) { |  181                                  &request)) { | 
|  167     return RespondNow(Error(kInvalidOperationsMessage)); |  182     return RespondNow(Error(kInvalidOperationsMessage)); | 
|  168   } |  183   } | 
|  169  |  184  | 
 |  185   service->copresence_apps().insert(extension_id()); | 
|  170   service->manager()->ExecuteReportRequest( |  186   service->manager()->ExecuteReportRequest( | 
|  171       request, |  187       request, | 
|  172       extension_id(), |  188       extension_id(), | 
|  173       base::Bind(&CopresenceExecuteFunction::SendResult, this)); |  189       base::Bind(&CopresenceExecuteFunction::SendResult, this)); | 
|  174   return RespondLater(); |  190   return RespondLater(); | 
|  175 } |  191 } | 
|  176  |  192  | 
|  177 void CopresenceExecuteFunction::SendResult( |  193 void CopresenceExecuteFunction::SendResult( | 
|  178     copresence::CopresenceStatus status) { |  194     copresence::CopresenceStatus status) { | 
|  179   api::copresence::ExecuteStatus api_status = |  195   api::copresence::ExecuteStatus api_status = | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
|  201   EXTENSION_FUNCTION_VALIDATE(params.get()); |  217   EXTENSION_FUNCTION_VALIDATE(params.get()); | 
|  202  |  218  | 
|  203   // The token may be set to empty, to clear it. |  219   // The token may be set to empty, to clear it. | 
|  204   // TODO(ckehoe): Scope the auth token appropriately (crbug/423517). |  220   // TODO(ckehoe): Scope the auth token appropriately (crbug/423517). | 
|  205   CopresenceService::GetFactoryInstance()->Get(browser_context()) |  221   CopresenceService::GetFactoryInstance()->Get(browser_context()) | 
|  206       ->set_auth_token(params->token); |  222       ->set_auth_token(params->token); | 
|  207   return RespondNow(NoArguments()); |  223   return RespondNow(NoArguments()); | 
|  208 } |  224 } | 
|  209  |  225  | 
|  210 }  // namespace extensions |  226 }  // namespace extensions | 
| OLD | NEW |