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

Side by Side Diff: components/rappor/log_uploader.h

Issue 49753002: RAPPOR implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: RapporMetrics StatsTest Created 6 years, 11 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
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_RAPPOR_LOG_UPLOADER_H_
6 #define COMPONENTS_RAPPOR_LOG_UPLOADER_H_
7
8 #include <queue>
9 #include <string>
10
11 #include "base/memory/scoped_ptr.h"
12 #include "base/time/time.h"
13 #include "base/timer/timer.h"
14 #include "net/url_request/url_fetcher.h"
15 #include "net/url_request/url_fetcher_delegate.h"
16 #include "net/url_request/url_request_context_getter.h"
17
18 namespace rappor {
19
20 // Handles uploading logs to an external server.
21 class LogUploader : public net::URLFetcherDelegate {
22 public:
23 // Constructor takes the server_url that logs should be uploaded to, the
24 // mime_type of the uploaded data, and request_context to create uploads
25 // with.
26 LogUploader(const std::string& server_url,
27 const std::string& mime_type,
28 net::URLRequestContextGetter* request_context);
29
30 ~LogUploader();
31
32 // Adds an entry to the queue of logs to be uploaded to the server.
33 void QueueLog(const std::string& log);
34
35 private:
36 // Starts transmission of the next log.
37 void StartScheduledUpload();
38
39 // Schedules a future call to StartScheduledUpload if one isn't already
40 // pending.
41 void ScheduleNextUpload();
42
43 // Increases the upload interval each time it's called, to handle the case
44 // where the server is having issues.
45 void BackOffUploadInterval();
46
47 // Implementation of net::URLFetcherDelegate. Called after transmission
48 // completes (either successfully or with failure).
49 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
50
51 // Called when the upload is completed.
52 void UploadFinished(bool server_is_healthy, bool more_logs_remaining);
53
54 // The server URL to upload logs to.
55 const std::string server_url_;
56
57 // The mime type to specify on uploaded logs.
58 const std::string mime_type_;
59
60 scoped_refptr<net::URLRequestContextGetter> request_context_;
61
62 // The outstanding transmission appears as a URL Fetch operation.
63 scoped_ptr<net::URLFetcher> current_fetch_;
64
65 // The logs that still need to be uploaded.
66 std::queue<std::string> queued_logs_;
67
68 base::OneShotTimer<LogUploader> upload_timer_;
69
70 // Indicates that the last triggered upload hasn't resolved yet.
71 bool has_callback_pending_;
72
73 // The interval to wait after an upload's URLFetcher completion before
74 // starting the next upload attempt.
75 base::TimeDelta upload_interval_;
76
77 DISALLOW_COPY_AND_ASSIGN(LogUploader);
78 };
79
80 } // namespace rappor
81
82 #endif // COMPONENTS_RAPPOR_LOG_UPLOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698