Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(471)

Side by Side Diff: chrome/browser/media/webrtc_logging_handler_host.cc

Issue 14329020: Implementing uploading of a WebRTC diagnostic log. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed build error on ChromeOS. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/media/webrtc_logging_handler_host.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/media/webrtc_logging_handler_host.h" 5 #include "chrome/browser/media/webrtc_logging_handler_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/prefs/pref_service.h"
10 #include "base/shared_memory.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/chromeos/settings/cros_settings.h"
13 #include "chrome/browser/chromeos/settings/cros_settings_names.h"
14 #include "chrome/browser/media/webrtc_log_uploader.h"
9 #include "chrome/common/media/webrtc_logging_messages.h" 15 #include "chrome/common/media/webrtc_logging_messages.h"
16 #include "chrome/common/pref_names.h"
17 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/content_browser_client.h"
19 #include "content/public/browser/render_process_host.h"
20 #include "net/url_request/url_request_context_getter.h"
10 21
11 using content::BrowserThread; 22 using content::BrowserThread;
12 23
24
13 #if defined(OS_ANDROID) 25 #if defined(OS_ANDROID)
14 const size_t kWebRtcLogSize = 1 * 1024 * 1024; // 1 MB 26 const size_t kWebRtcLogSize = 1 * 1024 * 1024; // 1 MB
15 #else 27 #else
16 const size_t kWebRtcLogSize = 6 * 1024 * 1024; // 6 MB 28 const size_t kWebRtcLogSize = 6 * 1024 * 1024; // 6 MB
17 #endif 29 #endif
18 30
19 WebRtcLoggingHandlerHost::WebRtcLoggingHandlerHost() { 31 WebRtcLoggingHandlerHost::WebRtcLoggingHandlerHost() {}
20 }
21 32
22 WebRtcLoggingHandlerHost::~WebRtcLoggingHandlerHost() { 33 WebRtcLoggingHandlerHost::~WebRtcLoggingHandlerHost() {}
23 }
24 34
25 void WebRtcLoggingHandlerHost::OnChannelClosing() { 35 void WebRtcLoggingHandlerHost::OnChannelClosing() {
36 UploadLog();
26 content::BrowserMessageFilter::OnChannelClosing(); 37 content::BrowserMessageFilter::OnChannelClosing();
27 } 38 }
28 39
29 void WebRtcLoggingHandlerHost::OnDestruct() const { 40 void WebRtcLoggingHandlerHost::OnDestruct() const {
30 BrowserThread::DeleteOnIOThread::Destruct(this); 41 BrowserThread::DeleteOnIOThread::Destruct(this);
31 } 42 }
32 43
33 bool WebRtcLoggingHandlerHost::OnMessageReceived(const IPC::Message& message, 44 bool WebRtcLoggingHandlerHost::OnMessageReceived(const IPC::Message& message,
34 bool* message_was_ok) { 45 bool* message_was_ok) {
35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
36 bool handled = true; 47 bool handled = true;
37 IPC_BEGIN_MESSAGE_MAP_EX(WebRtcLoggingHandlerHost, message, *message_was_ok) 48 IPC_BEGIN_MESSAGE_MAP_EX(WebRtcLoggingHandlerHost, message, *message_was_ok)
38 IPC_MESSAGE_HANDLER(WebRtcLoggingMsg_OpenLog, OnOpenLog) 49 IPC_MESSAGE_HANDLER(WebRtcLoggingMsg_OpenLog, OnOpenLog)
39 IPC_MESSAGE_UNHANDLED(handled = false) 50 IPC_MESSAGE_UNHANDLED(handled = false)
40 IPC_END_MESSAGE_MAP_EX() 51 IPC_END_MESSAGE_MAP_EX()
41 52
42 return handled; 53 return handled;
43 } 54 }
44 55
45 void WebRtcLoggingHandlerHost::OnOpenLog(const std::string& app_session_id, 56 void WebRtcLoggingHandlerHost::OnOpenLog(const std::string& app_session_id,
46 const std::string& app_url) { 57 const std::string& app_url) {
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
48 DCHECK(!base::SharedMemory::IsHandleValid(shared_memory_.handle())); 59 app_session_id_ = app_session_id;
60 app_url_ = app_url;
61 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(
62 &WebRtcLoggingHandlerHost::OpenLogIfAllowed, this));
63 }
49 64
50 if (!shared_memory_.CreateAndMapAnonymous(kWebRtcLogSize)) { 65 void WebRtcLoggingHandlerHost::OpenLogIfAllowed() {
66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
67
68 bool enabled = false;
69
70 // If the user permits metrics reporting / crash uploading with the checkbox
71 // in the prefs, we allow uploading automatically. We disable uploading
72 // completely for non-official builds.
73 #if defined(GOOGLE_CHROME_BUILD)
74 #if defined(OS_CHROMEOS)
75 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref,
76 &enabled);
77 #else
78 enabled = g_browser_process->local_state()->GetBoolean(
79 prefs::kMetricsReportingEnabled);
80 #endif // #if defined(OS_CHROMEOS)
81 #endif // defined(GOOGLE_CHROME_BUILD)
82 if (!enabled)
83 return;
84
85 if (!g_browser_process->webrtc_log_uploader()->ApplyForStartLogging())
86 return;
87
88 system_request_context_ = g_browser_process->system_request_context();
89 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind(
90 &WebRtcLoggingHandlerHost::DoOpenLog, this));
91 }
92
93 void WebRtcLoggingHandlerHost::DoOpenLog() {
94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
95 DCHECK(!shared_memory_);
96
97 shared_memory_.reset(new base::SharedMemory());
98
99 if (!shared_memory_->CreateAndMapAnonymous(kWebRtcLogSize)) {
51 DLOG(ERROR) << "Failed to create shared memory."; 100 DLOG(ERROR) << "Failed to create shared memory.";
52 Send(new WebRtcLoggingMsg_OpenLogFailed()); 101 Send(new WebRtcLoggingMsg_OpenLogFailed());
53 return; 102 return;
54 } 103 }
55 104
56 base::SharedMemoryHandle foreign_memory_handle; 105 base::SharedMemoryHandle foreign_memory_handle;
57 if (!shared_memory_.ShareToProcess(peer_handle(), 106 if (!shared_memory_->ShareToProcess(peer_handle(),
58 &foreign_memory_handle)) { 107 &foreign_memory_handle)) {
59 Send(new WebRtcLoggingMsg_OpenLogFailed()); 108 Send(new WebRtcLoggingMsg_OpenLogFailed());
60 return; 109 return;
61 } 110 }
62 111
63 app_session_id_ = app_session_id;
64 app_url_ = app_url;
65 Send(new WebRtcLoggingMsg_LogOpened(foreign_memory_handle, kWebRtcLogSize)); 112 Send(new WebRtcLoggingMsg_LogOpened(foreign_memory_handle, kWebRtcLogSize));
66 } 113 }
114
115 void WebRtcLoggingHandlerHost::UploadLog() {
116 if (!shared_memory_)
117 return;
118
119 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, base::Bind(
120 &WebRtcLogUploader::UploadLog,
121 base::Unretained(g_browser_process->webrtc_log_uploader()),
122 system_request_context_,
123 Passed(&shared_memory_),
124 kWebRtcLogSize,
125 app_session_id_,
126 app_url_));
127 }
OLDNEW
« no previous file with comments | « chrome/browser/media/webrtc_logging_handler_host.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698