OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/webrtc_logging_private/webrtc_logging_pr
ivate_api.h" | 5 #include "chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_pr
ivate_api.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/supports_user_data.h" |
| 9 #include "chrome/browser/media/webrtc_logging_handler_host.h" |
8 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/browser/render_process_host.h" |
| 12 #include "content/public/browser/render_view_host.h" |
| 13 #include "content/public/browser/web_contents.h" |
| 14 |
| 15 using content::BrowserThread; |
9 | 16 |
10 namespace extensions { | 17 namespace extensions { |
11 | 18 |
12 namespace SetMetaData = api::webrtc_logging_private::SetMetaData; | 19 namespace SetMetaData = api::webrtc_logging_private::SetMetaData; |
13 namespace SetUploadOnRenderClose = | 20 namespace SetUploadOnRenderClose = |
14 api::webrtc_logging_private::SetUploadOnRenderClose; | 21 api::webrtc_logging_private::SetUploadOnRenderClose; |
15 | 22 |
| 23 using api::webrtc_logging_private::MetaDataEntry; |
| 24 |
16 WebrtcLoggingPrivateSetMetaDataFunction:: | 25 WebrtcLoggingPrivateSetMetaDataFunction:: |
17 WebrtcLoggingPrivateSetMetaDataFunction() {} | 26 WebrtcLoggingPrivateSetMetaDataFunction() {} |
18 | 27 |
19 WebrtcLoggingPrivateSetMetaDataFunction:: | 28 WebrtcLoggingPrivateSetMetaDataFunction:: |
20 ~WebrtcLoggingPrivateSetMetaDataFunction() {} | 29 ~WebrtcLoggingPrivateSetMetaDataFunction() {} |
21 | 30 |
22 bool WebrtcLoggingPrivateSetMetaDataFunction::RunImpl() { | 31 bool WebrtcLoggingPrivateSetMetaDataFunction::RunImpl() { |
23 scoped_ptr<SetMetaData::Params> params(SetMetaData::Params::Create(*args_)); | 32 scoped_ptr<SetMetaData::Params> params(SetMetaData::Params::Create(*args_)); |
24 EXTENSION_FUNCTION_VALIDATE(params.get()); | 33 EXTENSION_FUNCTION_VALIDATE(params.get()); |
25 | 34 |
26 // TODO(grunell): Implement. | 35 content::RenderProcessHost* host = render_view_host()->GetProcess(); |
27 NOTIMPLEMENTED(); | 36 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( |
28 return false; | 37 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); |
| 38 |
| 39 std::map<std::string, std::string> meta_data; |
| 40 for (std::vector<linked_ptr<MetaDataEntry> >::const_iterator it = |
| 41 params->meta_data.begin(); it != params->meta_data.end(); ++it) { |
| 42 meta_data[(*it)->key] = (*it)->value; |
| 43 } |
| 44 |
| 45 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( |
| 46 &WebrtcLoggingPrivateSetMetaDataFunction::SetMetaDataCallback, this); |
| 47 |
| 48 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( |
| 49 &WebRtcLoggingHandlerHost::SetMetaData, webrtc_logging_handler_host, |
| 50 meta_data, callback)); |
| 51 |
| 52 return true; |
| 53 } |
| 54 |
| 55 void WebrtcLoggingPrivateSetMetaDataFunction::SetMetaDataCallback( |
| 56 bool success, const std::string& error_message) { |
| 57 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 58 if (!success) |
| 59 SetError(error_message); |
| 60 SendResponse(success); |
29 } | 61 } |
30 | 62 |
31 WebrtcLoggingPrivateStartFunction::WebrtcLoggingPrivateStartFunction() {} | 63 WebrtcLoggingPrivateStartFunction::WebrtcLoggingPrivateStartFunction() {} |
32 | 64 |
33 WebrtcLoggingPrivateStartFunction::~WebrtcLoggingPrivateStartFunction() {} | 65 WebrtcLoggingPrivateStartFunction::~WebrtcLoggingPrivateStartFunction() {} |
34 | 66 |
35 bool WebrtcLoggingPrivateStartFunction::RunImpl() { | 67 bool WebrtcLoggingPrivateStartFunction::RunImpl() { |
36 // TODO(grunell): Implement. | 68 content::RenderProcessHost* host = render_view_host()->GetProcess(); |
37 NOTIMPLEMENTED(); | 69 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( |
38 return false; | 70 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); |
| 71 |
| 72 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( |
| 73 &WebrtcLoggingPrivateStartFunction::StartCallback, this); |
| 74 |
| 75 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( |
| 76 &WebRtcLoggingHandlerHost::StartLogging, webrtc_logging_handler_host, |
| 77 callback)); |
| 78 |
| 79 return true; |
39 } | 80 } |
40 | 81 |
41 void WebrtcLoggingPrivateStartFunction::StartCallback(bool success) { | 82 void WebrtcLoggingPrivateStartFunction::StartCallback( |
| 83 bool success, const std::string& error_message) { |
42 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 84 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
43 // TODO(grunell): Implement set lastError. | 85 if (!success) |
44 NOTIMPLEMENTED(); | 86 SetError(error_message); |
45 SendResponse(success); | 87 SendResponse(success); |
46 } | 88 } |
47 | 89 |
48 WebrtcLoggingPrivateSetUploadOnRenderCloseFunction:: | 90 WebrtcLoggingPrivateSetUploadOnRenderCloseFunction:: |
49 WebrtcLoggingPrivateSetUploadOnRenderCloseFunction() {} | 91 WebrtcLoggingPrivateSetUploadOnRenderCloseFunction() {} |
50 | 92 |
51 WebrtcLoggingPrivateSetUploadOnRenderCloseFunction:: | 93 WebrtcLoggingPrivateSetUploadOnRenderCloseFunction:: |
52 ~WebrtcLoggingPrivateSetUploadOnRenderCloseFunction() {} | 94 ~WebrtcLoggingPrivateSetUploadOnRenderCloseFunction() {} |
53 | 95 |
54 bool WebrtcLoggingPrivateSetUploadOnRenderCloseFunction::RunImpl() { | 96 bool WebrtcLoggingPrivateSetUploadOnRenderCloseFunction::RunImpl() { |
55 scoped_ptr<SetUploadOnRenderClose::Params> params( | 97 scoped_ptr<SetUploadOnRenderClose::Params> params( |
56 SetUploadOnRenderClose::Params::Create(*args_)); | 98 SetUploadOnRenderClose::Params::Create(*args_)); |
57 EXTENSION_FUNCTION_VALIDATE(params.get()); | 99 EXTENSION_FUNCTION_VALIDATE(params.get()); |
58 | 100 |
59 // TODO(grunell): Implement. | 101 content::RenderProcessHost* host = render_view_host()->GetProcess(); |
60 NOTIMPLEMENTED(); | 102 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( |
61 return false; | 103 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); |
| 104 |
| 105 webrtc_logging_handler_host->set_upload_log_on_render_close( |
| 106 params->should_upload); |
| 107 |
| 108 return true; |
62 } | 109 } |
63 | 110 |
64 WebrtcLoggingPrivateStopFunction::WebrtcLoggingPrivateStopFunction() {} | 111 WebrtcLoggingPrivateStopFunction::WebrtcLoggingPrivateStopFunction() {} |
65 | 112 |
66 WebrtcLoggingPrivateStopFunction::~WebrtcLoggingPrivateStopFunction() {} | 113 WebrtcLoggingPrivateStopFunction::~WebrtcLoggingPrivateStopFunction() {} |
67 | 114 |
68 bool WebrtcLoggingPrivateStopFunction::RunImpl() { | 115 bool WebrtcLoggingPrivateStopFunction::RunImpl() { |
69 // TODO(grunell): Implement. | 116 content::RenderProcessHost* host = render_view_host()->GetProcess(); |
70 NOTIMPLEMENTED(); | 117 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( |
71 return false; | 118 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); |
| 119 |
| 120 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( |
| 121 &WebrtcLoggingPrivateStopFunction::StopCallback, this); |
| 122 |
| 123 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( |
| 124 &WebRtcLoggingHandlerHost::StopLogging, webrtc_logging_handler_host, |
| 125 callback)); |
| 126 |
| 127 return true; |
72 } | 128 } |
73 | 129 |
74 void WebrtcLoggingPrivateStopFunction::StopCallback(bool success) { | 130 void WebrtcLoggingPrivateStopFunction::StopCallback( |
| 131 bool success, const std::string& error_message) { |
75 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 132 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
76 // TODO(grunell): Implement set lastError. | 133 if (!success) |
77 NOTIMPLEMENTED(); | 134 SetError(error_message); |
78 SendResponse(success); | 135 SendResponse(success); |
79 } | 136 } |
80 | 137 |
81 WebrtcLoggingPrivateUploadFunction::WebrtcLoggingPrivateUploadFunction() {} | 138 WebrtcLoggingPrivateUploadFunction::WebrtcLoggingPrivateUploadFunction() {} |
82 | 139 |
83 WebrtcLoggingPrivateUploadFunction::~WebrtcLoggingPrivateUploadFunction() {} | 140 WebrtcLoggingPrivateUploadFunction::~WebrtcLoggingPrivateUploadFunction() {} |
84 | 141 |
85 bool WebrtcLoggingPrivateUploadFunction::RunImpl() { | 142 bool WebrtcLoggingPrivateUploadFunction::RunImpl() { |
86 // TODO(grunell): Implement. | 143 content::RenderProcessHost* host = render_view_host()->GetProcess(); |
87 NOTIMPLEMENTED(); | 144 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( |
88 return false; | 145 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); |
| 146 |
| 147 WebRtcLoggingHandlerHost::UploadDoneCallback callback = base::Bind( |
| 148 &WebrtcLoggingPrivateUploadFunction::UploadCallback, this); |
| 149 |
| 150 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( |
| 151 &WebRtcLoggingHandlerHost::UploadLog, webrtc_logging_handler_host, |
| 152 callback)); |
| 153 |
| 154 return true; |
89 } | 155 } |
90 | 156 |
91 void WebrtcLoggingPrivateUploadFunction::UploadCallback( | 157 void WebrtcLoggingPrivateUploadFunction::UploadCallback( |
92 bool success, std::string report_id) { | 158 bool success, const std::string& report_id, |
| 159 const std::string& error_message) { |
93 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 160 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
94 api::webrtc_logging_private::UploadResult result; | 161 if (success) { |
95 result.report_id = report_id; | 162 api::webrtc_logging_private::UploadResult result; |
96 // TODO(grunell): Implement set lastError. | 163 result.report_id = report_id; |
97 NOTIMPLEMENTED(); | 164 SetResult(result.ToValue().release()); |
| 165 } else { |
| 166 SetError(error_message); |
| 167 } |
98 SendResponse(success); | 168 SendResponse(success); |
99 } | 169 } |
100 | 170 |
101 WebrtcLoggingPrivateDiscardFunction::WebrtcLoggingPrivateDiscardFunction() {} | 171 WebrtcLoggingPrivateDiscardFunction::WebrtcLoggingPrivateDiscardFunction() {} |
102 | 172 |
103 WebrtcLoggingPrivateDiscardFunction::~WebrtcLoggingPrivateDiscardFunction() {} | 173 WebrtcLoggingPrivateDiscardFunction::~WebrtcLoggingPrivateDiscardFunction() {} |
104 | 174 |
105 bool WebrtcLoggingPrivateDiscardFunction::RunImpl() { | 175 bool WebrtcLoggingPrivateDiscardFunction::RunImpl() { |
106 // TODO(grunell): Implement. | 176 content::RenderProcessHost* host = render_view_host()->GetProcess(); |
107 NOTIMPLEMENTED(); | 177 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( |
108 return false; | 178 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); |
| 179 |
| 180 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( |
| 181 &WebrtcLoggingPrivateDiscardFunction::DiscardCallback, this); |
| 182 |
| 183 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( |
| 184 &WebRtcLoggingHandlerHost::DiscardLog, webrtc_logging_handler_host, |
| 185 callback)); |
| 186 |
| 187 return true; |
109 } | 188 } |
110 | 189 |
111 void WebrtcLoggingPrivateDiscardFunction::DiscardCallback(bool success) { | 190 void WebrtcLoggingPrivateDiscardFunction::DiscardCallback( |
| 191 bool success, const std::string& error_message) { |
112 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 192 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
113 // TODO(grunell): Implement set lastError. | 193 if (!success) |
114 NOTIMPLEMENTED(); | 194 SetError(error_message); |
115 SendResponse(success); | 195 SendResponse(success); |
116 } | 196 } |
117 | 197 |
118 } // namespace extensions | 198 } // namespace extensions |
OLD | NEW |