 Chromium Code Reviews
 Chromium Code Reviews Issue 2791983004:
  DBus MediaAnalyticsClient and media_perception pb.  (Closed)
    
  
    Issue 2791983004:
  DBus MediaAnalyticsClient and media_perception pb.  (Closed) 
  | OLD | NEW | 
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 | |
| 5 #include "extensions/browser/api/media_perception_private/media_perception_priva te_api.h" | |
| 6 | |
| 7 #include "extensions/browser/api/media_perception_private/media_perception_api_m anager.h" | |
| 8 #include "extensions/browser/extension_function.h" | |
| 9 | |
| 10 namespace media_perception = extensions::api::media_perception_private; | |
| 11 | |
| 12 namespace extensions { | |
| 13 | |
| 14 MediaPerceptionPrivateGetStateFunction :: | |
| 15 MediaPerceptionPrivateGetStateFunction() {} | |
| 16 | |
| 17 MediaPerceptionPrivateGetStateFunction :: | |
| 18 ~MediaPerceptionPrivateGetStateFunction() {} | |
| 19 | |
| 20 bool MediaPerceptionPrivateGetStateFunction::RunAsync() { | |
| 21 MediaPerceptionAPIManager* manager = | |
| 22 MediaPerceptionAPIManager::Get(browser_context()); | |
| 23 if (!manager) { | |
| 24 SetError("Can't get manager."); | |
| 25 return false; | |
| 26 } | |
| 27 manager->GetState(base::Bind( | |
| 28 &MediaPerceptionPrivateGetStateFunction::GetStateCallback, this)); | |
| 29 return true; | |
| 30 } | |
| 31 | |
| 32 void MediaPerceptionPrivateGetStateFunction::GetStateCallback( | |
| 33 bool succeeded, | |
| 34 media_perception::State state) { | |
| 35 if (!succeeded) { | |
| 36 SendResponse(false); | |
| 37 return; | |
| 38 } | |
| 39 SetResult(state.ToValue()); | |
| 40 SendResponse(true); | |
| 41 } | |
| 42 | |
| 43 MediaPerceptionPrivateSetStateFunction :: | |
| 44 MediaPerceptionPrivateSetStateFunction() {} | |
| 45 | |
| 46 MediaPerceptionPrivateSetStateFunction :: | |
| 47 ~MediaPerceptionPrivateSetStateFunction() {} | |
| 48 | |
| 49 bool MediaPerceptionPrivateSetStateFunction::RunAsync() { | |
| 50 std::unique_ptr<media_perception::SetState::Params> params = | |
| 51 media_perception::SetState::Params::Create(*args_); | |
| 52 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
| 
tbarzic
2017/05/05 21:10:41
Check params->state is a settable one here and ret
 
Luke Sorenson
2017/05/08 19:06:06
Done. In https://codereview.chromium.org/285835300
 | |
| 53 // Test triggering an onMediaPerception event. | |
| 54 MediaPerceptionAPIManager* manager = | |
| 55 MediaPerceptionAPIManager::Get(browser_context()); | |
| 56 if (!manager) { | |
| 57 SetError("Can't get manager."); | |
| 58 return false; | |
| 59 } | |
| 60 manager->SetState( | |
| 61 params->state, | |
| 62 base::Bind(&MediaPerceptionPrivateSetStateFunction::SetStateCallback, | |
| 63 this)); | |
| 64 return true; | |
| 65 } | |
| 66 | |
| 67 void MediaPerceptionPrivateSetStateFunction::SetStateCallback( | |
| 68 bool succeeded, | |
| 69 media_perception::State state) { | |
| 70 if (!succeeded) { | |
| 71 SendResponse(false); | |
| 72 return; | |
| 73 } | |
| 74 SetResult(state.ToValue()); | |
| 75 SendResponse(true); | |
| 76 } | |
| 77 | |
| 78 MediaPerceptionPrivateGetDiagnosticsFunction :: | |
| 79 MediaPerceptionPrivateGetDiagnosticsFunction() {} | |
| 80 | |
| 81 MediaPerceptionPrivateGetDiagnosticsFunction :: | |
| 82 ~MediaPerceptionPrivateGetDiagnosticsFunction() {} | |
| 83 | |
| 84 bool MediaPerceptionPrivateGetDiagnosticsFunction::RunAsync() { | |
| 85 MediaPerceptionAPIManager* manager = | |
| 86 MediaPerceptionAPIManager::Get(browser_context()); | |
| 87 if (!manager) { | |
| 88 SetError("Can't get manager."); | |
| 89 return false; | |
| 90 } | |
| 91 manager->GetDiagnostics(base::Bind( | |
| 92 &MediaPerceptionPrivateGetDiagnosticsFunction::GetDiagnosticsCallback, | |
| 93 this)); | |
| 94 return true; | |
| 95 } | |
| 96 | |
| 97 void MediaPerceptionPrivateGetDiagnosticsFunction::GetDiagnosticsCallback( | |
| 98 bool succeeded, | |
| 99 media_perception::Diagnostics diagnostics) { | |
| 100 if (!succeeded) { | |
| 101 SendResponse(false); | |
| 102 return; | |
| 103 } | |
| 104 SetResult(diagnostics.ToValue()); | |
| 105 SendResponse(true); | |
| 106 } | |
| 107 | |
| 108 } // namespace extensions | |
| OLD | NEW |