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 #ifndef CHROME_BROWSER_MEDIA_WEBRTC_LOGGING_HANDLER_HOST_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_WEBRTC_LOGGING_HANDLER_HOST_H_ |
6 #define CHROME_BROWSER_MEDIA_WEBRTC_LOGGING_HANDLER_HOST_H_ | 6 #define CHROME_BROWSER_MEDIA_WEBRTC_LOGGING_HANDLER_HOST_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
10 #include "content/public/browser/browser_message_filter.h" | 10 #include "content/public/browser/browser_message_filter.h" |
11 | 11 |
12 namespace net { | 12 namespace net { |
13 class URLRequestContextGetter; | 13 class URLRequestContextGetter; |
14 } // namespace net | 14 } // namespace net |
15 | 15 |
16 class RenderProcessHost; | 16 class RenderProcessHost; |
17 | 17 |
18 // WebRtcLoggingHandlerHost handles operations regarding the WebRTC logging: | 18 // WebRtcLoggingHandlerHost handles operations regarding the WebRTC logging: |
19 // - Opens a shared memory buffer that the handler in the render process | 19 // - Opens a shared memory buffer that the handler in the render process |
20 // writes to. | 20 // writes to. |
21 // - Detects when channel, i.e. renderer, is going away and triggers uploading | 21 // - Writes basic machine info to the log. |
22 // the log. | 22 // - Informs the handler in the render process when to stop logging. |
| 23 // - Closes the shared memory (and thereby discarding it) or triggers uploading |
| 24 // of the log. |
| 25 // - Detects when channel, i.e. renderer, is going away and possibly triggers |
| 26 // uploading the log. |
23 class WebRtcLoggingHandlerHost : public content::BrowserMessageFilter { | 27 class WebRtcLoggingHandlerHost : public content::BrowserMessageFilter { |
24 public: | 28 public: |
| 29 typedef base::Callback<void(bool, const std::string&)> GenericDoneCallback; |
| 30 typedef base::Callback<void(bool, const std::string&, const std::string&)> |
| 31 UploadDoneCallback; |
| 32 |
25 WebRtcLoggingHandlerHost(); | 33 WebRtcLoggingHandlerHost(); |
26 | 34 |
| 35 // Sets meta data that will be uploaded along with the log and also written |
| 36 // in the beginning of the log. Must be called on the IO thread before calling |
| 37 // StartLogging. |
| 38 void SetMetaData(const std::map<std::string, std::string>& meta_data, |
| 39 const GenericDoneCallback& callback); |
| 40 |
| 41 // Opens a log and starts logging. Must be called on the IO thread. |
| 42 void StartLogging(const GenericDoneCallback& callback); |
| 43 |
| 44 // Stops logging. Log will remain open until UploadLog or DiscardLog is |
| 45 // called. Must be called on the IO thread. |
| 46 void StopLogging(const GenericDoneCallback& callback); |
| 47 |
| 48 // Uploads the log and discards the local copy. May only be called after |
| 49 // logging has stopped. Must be called on the IO thread. |
| 50 void UploadLog(const UploadDoneCallback& callback); |
| 51 |
| 52 // Called by WebRtcLogUploader when uploading has finished. Must be called on |
| 53 // the IO thread. |
| 54 void UploadLogDone(); |
| 55 |
| 56 // Discards the log. May only be called after logging has stopped. Must be |
| 57 // called on the IO thread. |
| 58 void DiscardLog(const GenericDoneCallback& callback); |
| 59 |
| 60 // May be called on any thread. |upload_log_on_render_close_| is used |
| 61 // for decision making and it's OK if it changes before the execution based |
| 62 // on that decision has finished. |
| 63 void set_upload_log_on_render_close(bool should_upload) { |
| 64 upload_log_on_render_close_ = should_upload; |
| 65 } |
| 66 |
27 private: | 67 private: |
| 68 // States used for protecting from function calls made at non-allowed points |
| 69 // in time. For example, StartLogging() is only allowed in CLOSED state. |
| 70 // Transitions: SetMetaData(): CLOSED -> CLOSED. |
| 71 // StartLogging(): CLOSED -> STARTING. |
| 72 // Start done: STARTING -> STARTED. |
| 73 // StopLogging(): STARTED -> STOPPING. |
| 74 // Stop done: STOPPING -> STOPPED. |
| 75 // UploadLog(): STOPPED -> UPLOADING. |
| 76 // Upload done: UPLOADING -> CLOSED. |
| 77 // DiscardLog(): STOPPED -> CLOSED. |
| 78 enum LoggingState { |
| 79 CLOSED, // Logging not started, no log in memory. |
| 80 STARTING, // Start logging is in progress. |
| 81 STARTED, // Logging started. |
| 82 STOPPING, // Stop logging is in progress. |
| 83 STOPPED, // Logging has been stopped, log still open in memory. |
| 84 UPLOADING // Uploading log is in progress. |
| 85 }; |
| 86 |
28 friend class content::BrowserThread; | 87 friend class content::BrowserThread; |
29 friend class base::DeleteHelper<WebRtcLoggingHandlerHost>; | 88 friend class base::DeleteHelper<WebRtcLoggingHandlerHost>; |
30 | 89 |
31 virtual ~WebRtcLoggingHandlerHost(); | 90 virtual ~WebRtcLoggingHandlerHost(); |
32 | 91 |
33 // BrowserMessageFilter implementation. | 92 // BrowserMessageFilter implementation. |
34 virtual void OnChannelClosing() OVERRIDE; | 93 virtual void OnChannelClosing() OVERRIDE; |
35 virtual void OnDestruct() const OVERRIDE; | 94 virtual void OnDestruct() const OVERRIDE; |
36 virtual bool OnMessageReceived(const IPC::Message& message, | 95 virtual bool OnMessageReceived(const IPC::Message& message, |
37 bool* message_was_ok) OVERRIDE; | 96 bool* message_was_ok) OVERRIDE; |
38 | 97 |
39 void OnOpenLog(const std::string& app_session_id, const std::string& app_url); | 98 void OnLoggingStoppedInRenderer(); |
40 | 99 |
41 void OpenLogIfAllowed(); | 100 void StartLoggingIfAllowed(); |
42 void DoOpenLog(); | 101 void DoStartLogging(); |
43 void LogMachineInfo(); | 102 void LogMachineInfo(); |
44 void NotifyLogOpened(); | 103 void NotifyLoggingStarted(); |
45 | 104 |
46 void UploadLog(); | 105 void TriggerUploadLog(); |
| 106 |
| 107 void FireGenericDoneCallback(GenericDoneCallback* callback, |
| 108 bool success, |
| 109 const std::string& error_message); |
47 | 110 |
48 scoped_refptr<net::URLRequestContextGetter> system_request_context_; | 111 scoped_refptr<net::URLRequestContextGetter> system_request_context_; |
49 scoped_ptr<base::SharedMemory> shared_memory_; | 112 scoped_ptr<base::SharedMemory> shared_memory_; |
50 std::string app_session_id_; | 113 |
51 std::string app_url_; | 114 // These are only accessed on the IO thread, except when in STARTING state. In |
| 115 // this state we are protected since entering any function that alters the |
| 116 // state is not allowed. |
| 117 std::map<std::string, std::string> meta_data_; |
| 118 |
| 119 // These are only accessed on the IO thread. |
| 120 GenericDoneCallback start_callback_; |
| 121 GenericDoneCallback stop_callback_; |
| 122 UploadDoneCallback upload_callback_; |
| 123 |
| 124 // Only accessed on the IO thread, except when in STARTING, STOPPING or |
| 125 // UPLOADING state if the action fails and the state must be reset. In these |
| 126 // states however, we are protected since entering any function that alters |
| 127 // the state is not allowed. |
| 128 LoggingState logging_state_; |
| 129 |
| 130 // Only accessed on the IO thread. |
| 131 bool upload_log_on_render_close_; |
52 | 132 |
53 // This is the handle to be passed to the render process. It's stored so that | 133 // This is the handle to be passed to the render process. It's stored so that |
54 // it doesn't have to be passed on when posting messages between threads. | 134 // it doesn't have to be passed on when posting messages between threads. |
55 // It's only accessed on the IO thread. | 135 // It's only accessed on the IO thread. |
56 base::SharedMemoryHandle foreign_memory_handle_; | 136 base::SharedMemoryHandle foreign_memory_handle_; |
57 | 137 |
58 DISALLOW_COPY_AND_ASSIGN(WebRtcLoggingHandlerHost); | 138 DISALLOW_COPY_AND_ASSIGN(WebRtcLoggingHandlerHost); |
59 }; | 139 }; |
60 | 140 |
61 #endif // CHROME_BROWSER_MEDIA_WEBRTC_LOGGING_HANDLER_HOST_H_ | 141 #endif // CHROME_BROWSER_MEDIA_WEBRTC_LOGGING_HANDLER_HOST_H_ |
OLD | NEW |