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

Side by Side Diff: chrome/browser/media/webrtc_log_uploader.h

Issue 211033006: Move destruction of WebRtcLogUploader to post threads teardown. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Proper fix. Created 6 years, 9 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
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 #ifndef CHROME_BROWSER_MEDIA_WEBRTC_LOG_UPLOADER_H_ 5 #ifndef CHROME_BROWSER_MEDIA_WEBRTC_LOG_UPLOADER_H_
6 #define CHROME_BROWSER_MEDIA_WEBRTC_LOG_UPLOADER_H_ 6 #define CHROME_BROWSER_MEDIA_WEBRTC_LOG_UPLOADER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/platform_file.h"
15 #include "base/threading/thread_checker.h" 13 #include "base/threading/thread_checker.h"
16 #include "chrome/browser/media/webrtc_logging_handler_host.h" 14 #include "chrome/browser/media/webrtc_logging_handler_host.h"
17 #include "net/url_request/url_fetcher_delegate.h" 15 #include "net/url_request/url_fetcher_delegate.h"
18 16
19 class Profile; 17 class Profile;
20 18
21 namespace base { 19 namespace base {
22 class SharedMemory; 20 class SharedMemory;
23 } 21 }
24 22
25 namespace net { 23 namespace net {
26 class URLFetcher; 24 class URLFetcher;
27 class URLRequestContextGetter;
28 } 25 }
29 26
30 typedef struct z_stream_s z_stream; 27 typedef struct z_stream_s z_stream;
31 28
32 // Used when uploading is done to perform post-upload actions. 29 // Used when uploading is done to perform post-upload actions.
33 typedef struct { 30 typedef struct {
34 base::FilePath upload_list_path; 31 base::FilePath upload_list_path;
35 WebRtcLoggingHandlerHost::UploadDoneCallback callback; 32 WebRtcLoggingHandlerHost::UploadDoneCallback callback;
36 scoped_refptr<WebRtcLoggingHandlerHost> host; 33 scoped_refptr<WebRtcLoggingHandlerHost> host;
37 } WebRtcLogUploadDoneData; 34 } WebRtcLogUploadDoneData;
38 35
39 class WebRtcLogURLRequestContextGetter;
40
41 // WebRtcLogUploader uploads WebRTC logs, keeps count of how many logs have 36 // WebRtcLogUploader uploads WebRTC logs, keeps count of how many logs have
42 // been started and denies further logs if a limit is reached. It also adds 37 // been started and denies further logs if a limit is reached. It also adds
43 // the timestamp and report ID of the uploded log to a text file. There must 38 // the timestamp and report ID of the uploded log to a text file. There must
44 // only be one object of this type. 39 // only be one object of this type.
45 class WebRtcLogUploader : public net::URLFetcherDelegate { 40 class WebRtcLogUploader : public net::URLFetcherDelegate {
46 public: 41 public:
47 WebRtcLogUploader(); 42 WebRtcLogUploader();
48 virtual ~WebRtcLogUploader(); 43 virtual ~WebRtcLogUploader();
49 44
50 // net::URLFetcherDelegate implementation. 45 // net::URLFetcherDelegate implementation.
(...skipping 11 matching lines...) Expand all
62 // After this function has been called, a new permission must be granted. 57 // After this function has been called, a new permission must be granted.
63 // Call either this function or LoggingStoppedDoUpload(). 58 // Call either this function or LoggingStoppedDoUpload().
64 void LoggingStoppedDontUpload(); 59 void LoggingStoppedDontUpload();
65 60
66 // Notifies that that logging has stopped and that the log should be uploaded. 61 // Notifies that that logging has stopped and that the log should be uploaded.
67 // Decreases log count. May only be called if permission to log has been 62 // Decreases log count. May only be called if permission to log has been
68 // granted by calling ApplyForStartLogging() and getting true in return. After 63 // granted by calling ApplyForStartLogging() and getting true in return. After
69 // this function has been called, a new permission must be granted. Call 64 // this function has been called, a new permission must be granted. Call
70 // either this function or LoggingStoppedDontUpload(). 65 // either this function or LoggingStoppedDontUpload().
71 void LoggingStoppedDoUpload( 66 void LoggingStoppedDoUpload(
72 net::URLRequestContextGetter* request_context,
73 scoped_ptr<unsigned char[]> log_buffer, 67 scoped_ptr<unsigned char[]> log_buffer,
74 uint32 length, 68 uint32 length,
75 const std::map<std::string, std::string>& meta_data, 69 const std::map<std::string, std::string>& meta_data,
76 const WebRtcLogUploadDoneData& upload_done_data); 70 const WebRtcLogUploadDoneData& upload_done_data);
77 71
72 // Cancels URL fetcher operation by resetting |url_fetcher_|. This cancels any
73 // pending uploads and releases SystemURLRequestContextGetter references.
74 void CancelURLFetcherOperations();
75
78 // For testing purposes. If called, the multipart will not be uploaded, but 76 // For testing purposes. If called, the multipart will not be uploaded, but
79 // written to |post_data_| instead. 77 // written to |post_data_| instead.
80 void OverrideUploadWithBufferForTesting(std::string* post_data) { 78 void OverrideUploadWithBufferForTesting(std::string* post_data) {
81 post_data_ = post_data; 79 post_data_ = post_data;
82 } 80 }
83 81
84 private: 82 private:
85 FRIEND_TEST_ALL_PREFIXES(WebRtcLogUploaderTest, 83 FRIEND_TEST_ALL_PREFIXES(WebRtcLogUploaderTest,
86 AddUploadedLogInfoToUploadListFile); 84 AddUploadedLogInfoToUploadListFile);
87 85
88 // Sets up a multipart body to be uploaded. The body is produced according 86 // Sets up a multipart body to be uploaded. The body is produced according
89 // to RFC 2046. 87 // to RFC 2046.
90 void SetupMultipart(std::string* post_data, uint8* log_buffer, 88 void SetupMultipart(std::string* post_data, uint8* log_buffer,
91 uint32 log_buffer_length, 89 uint32 log_buffer_length,
92 const std::map<std::string, std::string>& meta_data); 90 const std::map<std::string, std::string>& meta_data);
93 91
94 void AddLogData(std::string* post_data, uint8* log_buffer, 92 void AddLogData(std::string* post_data, uint8* log_buffer,
95 uint32 log_buffer_length); 93 uint32 log_buffer_length);
96 void CompressLog(std::string* post_data, uint8* input, uint32 input_size); 94 void CompressLog(std::string* post_data, uint8* input, uint32 input_size);
97 void ResizeForNextOutput(std::string* post_data, z_stream* stream); 95 void ResizeForNextOutput(std::string* post_data, z_stream* stream);
98 96
99 void CreateAndStartURLFetcher( 97 void CreateAndStartURLFetcher(
100 scoped_refptr<net::URLRequestContextGetter> request_context,
101 const WebRtcLogUploadDoneData& upload_done_data, 98 const WebRtcLogUploadDoneData& upload_done_data,
102 scoped_ptr<std::string> post_data); 99 scoped_ptr<std::string> post_data);
103 100
104 void DecreaseLogCount(); 101 void DecreaseLogCount();
105 102
106 // Append information (time and report ID) about this uploaded log to a log 103 // Append information (time and report ID) about this uploaded log to a log
107 // list file, limited to |kLogListLimitLines| entries. This list is used for 104 // list file, limited to |kLogListLimitLines| entries. This list is used for
108 // viewing the uploaded logs under chrome://webrtc-logs, see 105 // viewing the uploaded logs under chrome://webrtc-logs, see
109 // WebRtcLogUploadList. The list has the format 106 // WebRtcLogUploadList. The list has the format
110 // time,id 107 // time,id
111 // time,id 108 // time,id
112 // etc. 109 // etc.
113 // where each line represents an uploaded log and "time" is Unix time. 110 // where each line represents an uploaded log and "time" is Unix time.
114 void AddUploadedLogInfoToUploadListFile( 111 void AddUploadedLogInfoToUploadListFile(
115 const base::FilePath& upload_list_path, 112 const base::FilePath& upload_list_path,
116 const std::string& report_id); 113 const std::string& report_id);
117 114
118 void NotifyUploadDone(int response_code, 115 void NotifyUploadDone(int response_code,
119 const std::string& report_id, 116 const std::string& report_id,
120 const WebRtcLogUploadDoneData& upload_done_data); 117 const WebRtcLogUploadDoneData& upload_done_data);
121 118
122 // This is the UI thread for Chromium. Some other thread for tests. 119 // This is the UI thread for Chromium. Some other thread for tests.
123 base::ThreadChecker create_thread_checker_; 120 base::ThreadChecker create_thread_checker_;
124 121
125 // This is the FILE thread for Chromium. Some other thread for tests. 122 // This is the FILE thread for Chromium. Some other thread for tests.
126 base::ThreadChecker file_thread_checker_; 123 base::ThreadChecker file_thread_checker_;
127 124
125 // Keeps track of number of currently open logs. Must be accessed on the UI
126 // thread.
128 int log_count_; 127 int log_count_;
129 128
129 // The URLFetchers used for uploading. Must be accessed on the UI thread.
130 typedef std::vector<scoped_ptr<net::URLFetcher> > URLFetcherVector;
131 URLFetcherVector url_fetchers_;
132
130 // For testing purposes, see OverrideUploadWithBufferForTesting. Only accessed 133 // For testing purposes, see OverrideUploadWithBufferForTesting. Only accessed
131 // on the FILE thread. 134 // on the FILE thread.
132 std::string* post_data_; 135 std::string* post_data_;
133 136
134 typedef std::map<const net::URLFetcher*, WebRtcLogUploadDoneData> 137 typedef std::map<const net::URLFetcher*, WebRtcLogUploadDoneData>
135 UploadDoneDataMap; 138 UploadDoneDataMap;
136 // Only accessed on the UI thread. 139 // Only accessed on the UI thread.
137 UploadDoneDataMap upload_done_data_; 140 UploadDoneDataMap upload_done_data_;
138 141
139 DISALLOW_COPY_AND_ASSIGN(WebRtcLogUploader); 142 DISALLOW_COPY_AND_ASSIGN(WebRtcLogUploader);
140 }; 143 };
141 144
142 #endif // CHROME_BROWSER_MEDIA_WEBRTC_LOG_UPLOADER_H_ 145 #endif // CHROME_BROWSER_MEDIA_WEBRTC_LOG_UPLOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698