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 |
16 WebrtcLoggingPrivateSetMetaDataFunction:: | 23 WebrtcLoggingPrivateSetMetaDataFunction:: |
17 WebrtcLoggingPrivateSetMetaDataFunction() {} | 24 WebrtcLoggingPrivateSetMetaDataFunction() {} |
18 | 25 |
19 WebrtcLoggingPrivateSetMetaDataFunction:: | 26 WebrtcLoggingPrivateSetMetaDataFunction:: |
20 ~WebrtcLoggingPrivateSetMetaDataFunction() {} | 27 ~WebrtcLoggingPrivateSetMetaDataFunction() {} |
21 | 28 |
22 bool WebrtcLoggingPrivateSetMetaDataFunction::RunImpl() { | 29 bool WebrtcLoggingPrivateSetMetaDataFunction::RunImpl() { |
23 scoped_ptr<SetMetaData::Params> params(SetMetaData::Params::Create(*args_)); | 30 scoped_ptr<SetMetaData::Params> params(SetMetaData::Params::Create(*args_)); |
24 EXTENSION_FUNCTION_VALIDATE(params.get()); | 31 EXTENSION_FUNCTION_VALIDATE(params.get()); |
25 | 32 |
26 // TODO(grunell): Implement. | 33 content::RenderProcessHost* host = render_view_host()->GetProcess(); |
27 NOTIMPLEMENTED(); | 34 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( |
28 return false; | 35 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); |
36 | |
37 std::map<std::string, std::string> meta_data; | |
38 std::vector<linked_ptr<api::webrtc_logging_private::MetaDataEntry> >::iterator | |
no longer working on chromium
2013/10/01 08:41:42
Put it in the scope of for loop, and use const_ite
Henrik Grunell
2013/10/02 12:47:18
Done.
| |
39 it = params->meta_data.begin(); | |
40 for (; it != params->meta_data.end(); ++it) | |
41 meta_data[(*it)->key] = (*it)->value; | |
42 | |
43 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( | |
44 &WebrtcLoggingPrivateSetMetaDataFunction::SetMetaDataCallback, this); | |
45 | |
46 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | |
47 &WebRtcLoggingHandlerHost::SetMetaData, webrtc_logging_handler_host, | |
48 meta_data, callback)); | |
Jói
2013/09/27 14:39:53
Just noting it here, probably not worth optimizing
Henrik Grunell
2013/10/02 12:47:18
Yes, it's expected to be in the order of 5 entries
| |
49 | |
50 return true; | |
51 } | |
52 | |
53 void WebrtcLoggingPrivateSetMetaDataFunction::SetMetaDataCallback( | |
54 bool success, std::string error_message) { | |
55 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
56 if (!success) | |
57 SetError(error_message); | |
58 SendResponse(success); | |
29 } | 59 } |
30 | 60 |
31 WebrtcLoggingPrivateStartFunction::WebrtcLoggingPrivateStartFunction() {} | 61 WebrtcLoggingPrivateStartFunction::WebrtcLoggingPrivateStartFunction() {} |
32 | 62 |
33 WebrtcLoggingPrivateStartFunction::~WebrtcLoggingPrivateStartFunction() {} | 63 WebrtcLoggingPrivateStartFunction::~WebrtcLoggingPrivateStartFunction() {} |
34 | 64 |
35 bool WebrtcLoggingPrivateStartFunction::RunImpl() { | 65 bool WebrtcLoggingPrivateStartFunction::RunImpl() { |
36 // TODO(grunell): Implement. | 66 content::RenderProcessHost* host = render_view_host()->GetProcess(); |
37 NOTIMPLEMENTED(); | 67 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( |
38 return false; | 68 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); |
69 | |
70 std::string app_url; | |
71 content::WebContents* web_contents = | |
72 content::WebContents::FromRenderViewHost(render_view_host()); | |
73 if (web_contents) | |
74 app_url = web_contents->GetLastCommittedURL().spec(); | |
75 | |
76 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( | |
77 &WebrtcLoggingPrivateStartFunction::StartCallback, this); | |
78 | |
79 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | |
80 &WebRtcLoggingHandlerHost::StartLogging, webrtc_logging_handler_host, | |
81 app_url, callback)); | |
82 | |
83 return true; | |
39 } | 84 } |
40 | 85 |
41 void WebrtcLoggingPrivateStartFunction::StartCallback(bool success) { | 86 void WebrtcLoggingPrivateStartFunction::StartCallback( |
87 bool success, std::string error_message) { | |
42 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 88 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
43 // TODO(grunell): Implement set lastError. | 89 if (!success) |
44 NOTIMPLEMENTED(); | 90 SetError(error_message); |
45 SendResponse(success); | 91 SendResponse(success); |
46 } | 92 } |
47 | 93 |
48 WebrtcLoggingPrivateSetUploadOnRenderCloseFunction:: | 94 WebrtcLoggingPrivateSetUploadOnRenderCloseFunction:: |
49 WebrtcLoggingPrivateSetUploadOnRenderCloseFunction() {} | 95 WebrtcLoggingPrivateSetUploadOnRenderCloseFunction() {} |
50 | 96 |
51 WebrtcLoggingPrivateSetUploadOnRenderCloseFunction:: | 97 WebrtcLoggingPrivateSetUploadOnRenderCloseFunction:: |
52 ~WebrtcLoggingPrivateSetUploadOnRenderCloseFunction() {} | 98 ~WebrtcLoggingPrivateSetUploadOnRenderCloseFunction() {} |
53 | 99 |
54 bool WebrtcLoggingPrivateSetUploadOnRenderCloseFunction::RunImpl() { | 100 bool WebrtcLoggingPrivateSetUploadOnRenderCloseFunction::RunImpl() { |
55 scoped_ptr<SetUploadOnRenderClose::Params> params( | 101 scoped_ptr<SetUploadOnRenderClose::Params> params( |
56 SetUploadOnRenderClose::Params::Create(*args_)); | 102 SetUploadOnRenderClose::Params::Create(*args_)); |
57 EXTENSION_FUNCTION_VALIDATE(params.get()); | 103 EXTENSION_FUNCTION_VALIDATE(params.get()); |
58 | 104 |
59 // TODO(grunell): Implement. | 105 content::RenderProcessHost* host = render_view_host()->GetProcess(); |
60 NOTIMPLEMENTED(); | 106 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( |
61 return false; | 107 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); |
108 | |
109 webrtc_logging_handler_host->set_upload_log_on_render_close( | |
110 params->should_upload); | |
111 | |
112 return true; | |
62 } | 113 } |
63 | 114 |
64 WebrtcLoggingPrivateStopFunction::WebrtcLoggingPrivateStopFunction() {} | 115 WebrtcLoggingPrivateStopFunction::WebrtcLoggingPrivateStopFunction() {} |
65 | 116 |
66 WebrtcLoggingPrivateStopFunction::~WebrtcLoggingPrivateStopFunction() {} | 117 WebrtcLoggingPrivateStopFunction::~WebrtcLoggingPrivateStopFunction() {} |
67 | 118 |
68 bool WebrtcLoggingPrivateStopFunction::RunImpl() { | 119 bool WebrtcLoggingPrivateStopFunction::RunImpl() { |
69 // TODO(grunell): Implement. | 120 content::RenderProcessHost* host = render_view_host()->GetProcess(); |
70 NOTIMPLEMENTED(); | 121 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( |
71 return false; | 122 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); |
123 | |
124 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( | |
125 &WebrtcLoggingPrivateStopFunction::StopCallback, this); | |
126 | |
127 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | |
128 &WebRtcLoggingHandlerHost::StopLogging, webrtc_logging_handler_host, | |
129 callback)); | |
130 | |
131 return true; | |
72 } | 132 } |
73 | 133 |
74 void WebrtcLoggingPrivateStopFunction::StopCallback(bool success) { | 134 void WebrtcLoggingPrivateStopFunction::StopCallback( |
135 bool success, std::string error_message) { | |
75 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 136 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
76 // TODO(grunell): Implement set lastError. | 137 if (!success) |
77 NOTIMPLEMENTED(); | 138 SetError(error_message); |
78 SendResponse(success); | 139 SendResponse(success); |
79 } | 140 } |
80 | 141 |
81 WebrtcLoggingPrivateUploadFunction::WebrtcLoggingPrivateUploadFunction() {} | 142 WebrtcLoggingPrivateUploadFunction::WebrtcLoggingPrivateUploadFunction() {} |
82 | 143 |
83 WebrtcLoggingPrivateUploadFunction::~WebrtcLoggingPrivateUploadFunction() {} | 144 WebrtcLoggingPrivateUploadFunction::~WebrtcLoggingPrivateUploadFunction() {} |
84 | 145 |
85 bool WebrtcLoggingPrivateUploadFunction::RunImpl() { | 146 bool WebrtcLoggingPrivateUploadFunction::RunImpl() { |
86 // TODO(grunell): Implement. | 147 content::RenderProcessHost* host = render_view_host()->GetProcess(); |
87 NOTIMPLEMENTED(); | 148 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( |
88 return false; | 149 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); |
150 | |
151 WebRtcLoggingHandlerHost::UploadDoneCallback callback = base::Bind( | |
152 &WebrtcLoggingPrivateUploadFunction::UploadCallback, this); | |
153 | |
154 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | |
155 &WebRtcLoggingHandlerHost::UploadLog, webrtc_logging_handler_host, | |
156 callback)); | |
157 | |
158 return true; | |
89 } | 159 } |
90 | 160 |
91 void WebrtcLoggingPrivateUploadFunction::UploadCallback( | 161 void WebrtcLoggingPrivateUploadFunction::UploadCallback( |
92 bool success, std::string report_id) { | 162 bool success, std::string report_id, std::string error_message) { |
93 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 163 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
94 api::webrtc_logging_private::UploadResult result; | 164 if (success) { |
95 result.report_id = report_id; | 165 api::webrtc_logging_private::UploadResult result; |
96 // TODO(grunell): Implement set lastError. | 166 result.report_id = report_id; |
97 NOTIMPLEMENTED(); | 167 SetResult(result.ToValue().release()); |
168 } else { | |
169 SetError(error_message); | |
170 } | |
98 SendResponse(success); | 171 SendResponse(success); |
99 } | 172 } |
100 | 173 |
101 WebrtcLoggingPrivateDiscardFunction::WebrtcLoggingPrivateDiscardFunction() {} | 174 WebrtcLoggingPrivateDiscardFunction::WebrtcLoggingPrivateDiscardFunction() {} |
102 | 175 |
103 WebrtcLoggingPrivateDiscardFunction::~WebrtcLoggingPrivateDiscardFunction() {} | 176 WebrtcLoggingPrivateDiscardFunction::~WebrtcLoggingPrivateDiscardFunction() {} |
104 | 177 |
105 bool WebrtcLoggingPrivateDiscardFunction::RunImpl() { | 178 bool WebrtcLoggingPrivateDiscardFunction::RunImpl() { |
106 // TODO(grunell): Implement. | 179 content::RenderProcessHost* host = render_view_host()->GetProcess(); |
107 NOTIMPLEMENTED(); | 180 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( |
108 return false; | 181 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); |
182 | |
183 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( | |
184 &WebrtcLoggingPrivateDiscardFunction::DiscardCallback, this); | |
185 | |
186 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | |
187 &WebRtcLoggingHandlerHost::DiscardLog, webrtc_logging_handler_host, | |
188 callback)); | |
189 | |
190 return true; | |
109 } | 191 } |
110 | 192 |
111 void WebrtcLoggingPrivateDiscardFunction::DiscardCallback(bool success) { | 193 void WebrtcLoggingPrivateDiscardFunction::DiscardCallback( |
194 bool success, std::string error_message) { | |
112 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 195 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
113 // TODO(grunell): Implement set lastError. | 196 if (!success) |
114 NOTIMPLEMENTED(); | 197 SetError(error_message); |
115 SendResponse(success); | 198 SendResponse(success); |
116 } | 199 } |
117 | 200 |
118 } // namespace extensions | 201 } // namespace extensions |
OLD | NEW |