OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "content/browser/renderer_host/webrtc_logging_handler_host.h" | 5 #include "content/browser/renderer_host/webrtc_logging_handler_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 //#include "base/command_line.h" |
| 9 //#include "base/prefs/pref_service.h" |
8 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 //#include "chrome/browser/browser_process.h" |
| 12 //#include "chrome/browser/webrtc_log_upload_manager.h" |
| 13 //#include "chrome/common/chrome_switches.h" |
| 14 //#include "chrome/common/pref_names.h" |
9 #include "content/common/webrtc_logging_messages.h" | 15 #include "content/common/webrtc_logging_messages.h" |
| 16 #include "content/public/browser/content_browser_client.h" |
10 | 17 |
11 namespace content { | 18 namespace content { |
12 | 19 |
13 const size_t kWebRtcLogSize = 6 * 1024 * 1024; // 6 MB | 20 const size_t kWebRtcLogSize = 6 * 1024 * 1024; // 6 MB |
14 | 21 |
15 WebRtcLoggingHandlerHost::WebRtcLoggingHandlerHost() { | 22 WebRtcLoggingHandlerHost::WebRtcLoggingHandlerHost() |
| 23 : shared_memory_(NULL) { |
16 } | 24 } |
17 | 25 |
18 WebRtcLoggingHandlerHost::~WebRtcLoggingHandlerHost() { | 26 WebRtcLoggingHandlerHost::~WebRtcLoggingHandlerHost() { |
| 27 // |shared_memory_| should have been handed to upload manager (and NULL here). |
| 28 // Delete it in case it wasn't. |
| 29 delete shared_memory_; |
19 } | 30 } |
20 | 31 |
21 void WebRtcLoggingHandlerHost::OnChannelClosing() { | 32 void WebRtcLoggingHandlerHost::OnChannelClosing() { |
| 33 UploadLog(); |
22 BrowserMessageFilter::OnChannelClosing(); | 34 BrowserMessageFilter::OnChannelClosing(); |
23 } | 35 } |
24 | 36 |
25 void WebRtcLoggingHandlerHost::OnDestruct() const { | 37 void WebRtcLoggingHandlerHost::OnDestruct() const { |
26 BrowserThread::DeleteOnIOThread::Destruct(this); | 38 BrowserThread::DeleteOnIOThread::Destruct(this); |
27 } | 39 } |
28 | 40 |
29 bool WebRtcLoggingHandlerHost::OnMessageReceived(const IPC::Message& message, | 41 bool WebRtcLoggingHandlerHost::OnMessageReceived(const IPC::Message& message, |
30 bool* message_was_ok) { | 42 bool* message_was_ok) { |
31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
32 bool handled = true; | 44 bool handled = true; |
33 IPC_BEGIN_MESSAGE_MAP_EX(WebRtcLoggingHandlerHost, message, *message_was_ok) | 45 IPC_BEGIN_MESSAGE_MAP_EX(WebRtcLoggingHandlerHost, message, *message_was_ok) |
34 IPC_MESSAGE_HANDLER(WebRtcLoggingMsg_OpenLog, OnOpenLog) | 46 IPC_MESSAGE_HANDLER(WebRtcLoggingMsg_OpenLog, OnOpenLog) |
35 IPC_MESSAGE_UNHANDLED(handled = false) | 47 IPC_MESSAGE_UNHANDLED(handled = false) |
36 IPC_END_MESSAGE_MAP_EX() | 48 IPC_END_MESSAGE_MAP_EX() |
37 | 49 |
38 return handled; | 50 return handled; |
39 } | 51 } |
40 | 52 |
41 void WebRtcLoggingHandlerHost::OnOpenLog() { | 53 void WebRtcLoggingHandlerHost::OnOpenLog() { |
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
43 DCHECK(!base::SharedMemory::IsHandleValid(shared_memory_.handle())); | 55 DCHECK(!shared_memory_); |
44 | 56 |
45 if (!shared_memory_.CreateAndMapAnonymous(kWebRtcLogSize)) { | 57 shared_memory_ = new base::SharedMemory(); |
| 58 |
| 59 if (!shared_memory_->CreateAndMapAnonymous(kWebRtcLogSize)) { |
46 DLOG(ERROR) << "Failed to create shared memory."; | 60 DLOG(ERROR) << "Failed to create shared memory."; |
47 Send(new WebRtcLoggingMsg_OpenLogFailed()); | 61 Send(new WebRtcLoggingMsg_OpenLogFailed()); |
48 return; | 62 return; |
49 } | 63 } |
50 | 64 |
51 base::SharedMemoryHandle foreign_memory_handle; | 65 base::SharedMemoryHandle foreign_memory_handle; |
52 if (!shared_memory_.ShareToProcess(peer_handle(), | 66 if (!shared_memory_->ShareToProcess(peer_handle(), |
53 &foreign_memory_handle)) { | 67 &foreign_memory_handle)) { |
54 Send(new WebRtcLoggingMsg_OpenLogFailed()); | 68 Send(new WebRtcLoggingMsg_OpenLogFailed()); |
55 return; | 69 return; |
56 } | 70 } |
57 | 71 |
58 Send(new WebRtcLoggingMsg_LogOpened(foreign_memory_handle, kWebRtcLogSize)); | 72 Send(new WebRtcLoggingMsg_LogOpened(foreign_memory_handle, kWebRtcLogSize)); |
59 } | 73 } |
60 | 74 |
| 75 bool WebRtcLoggingHandlerHost::IsUploadingEnabled() { |
| 76 // TODO(grunell): Move to chrome. |
| 77 /* |
| 78 // If the user permits metrics reporting / crash uploading with the checkbox |
| 79 // in the prefs, we allow uploading automatically. We disable uploading |
| 80 // completely for non-official builds. This can be forced with a flag. |
| 81 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 82 if (command_line->HasSwitch(switches::kEnableMetricsReportingForTesting)) |
| 83 return true; |
| 84 |
| 85 bool enabled = false; |
| 86 |
| 87 #if defined(GOOGLE_CHROME_BUILD) |
| 88 #if defined(OS_CHROMEOS) |
| 89 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, |
| 90 &enabled); |
| 91 #else |
| 92 // TODO(grunell): Fails, has to be on UI thread. |
| 93 enabled = g_browser_process->local_state()->GetBoolean( |
| 94 prefs::kMetricsReportingEnabled); |
| 95 #endif // #if defined(OS_CHROMEOS) |
| 96 #endif // defined(GOOGLE_CHROME_BUILD) |
| 97 |
| 98 return enabled; |
| 99 */ |
| 100 return true; |
| 101 } |
| 102 |
| 103 void WebRtcLoggingHandlerHost::UploadLog() { |
| 104 // Check if logging has been enabled. |
| 105 if (!shared_memory_) |
| 106 return; |
| 107 |
| 108 GetContentClient()->browser()->UploadWebRtcLog(shared_memory_, |
| 109 kWebRtcLogSize); |
| 110 shared_memory_ = NULL; |
| 111 } |
| 112 |
61 } // namespace content | 113 } // namespace content |
OLD | NEW |