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