Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 COMPONENTS_DOMAIN_RELIABILITY_CONTEXT_H_ | 5 #ifndef COMPONENTS_DOMAIN_RELIABILITY_CONTEXT_H_ |
| 6 #define COMPONENTS_DOMAIN_RELIABILITY_CONTEXT_H_ | 6 #define COMPONENTS_DOMAIN_RELIABILITY_CONTEXT_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <map> | 9 #include <map> |
|
Ryan Sleevi
2014/04/25 01:00:02
IWYU: vector (line 48)
DIWYDU: delete map - you do
Deprecated (see juliatuttle)
2014/04/28 22:01:13
Done.
| |
| 10 | 10 |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
|
Ryan Sleevi
2014/04/25 01:00:02
IWYU: I don't see any refcounting going on here.
Deprecated (see juliatuttle)
2014/04/28 22:01:13
Whoops. This used to take a URLRequestContextGette
| |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "components/domain_reliability/beacon.h" | 15 #include "components/domain_reliability/beacon.h" |
| 16 #include "components/domain_reliability/config.h" | 16 #include "components/domain_reliability/config.h" |
|
Ryan Sleevi
2014/04/25 01:00:02
Normally you'd be able to forward declare this, if
Deprecated (see juliatuttle)
2014/04/28 22:01:13
Are you saying I should rearrange it so I can?
| |
| 17 #include "components/domain_reliability/domain_reliability_export.h" | 17 #include "components/domain_reliability/domain_reliability_export.h" |
| 18 #include "components/domain_reliability/scheduler.h" | 18 #include "components/domain_reliability/scheduler.h" |
| 19 #include "components/domain_reliability/uploader.h" | 19 #include "components/domain_reliability/uploader.h" |
| 20 #include "components/domain_reliability/util.h" | 20 #include "components/domain_reliability/util.h" |
| 21 | 21 |
| 22 class GURL; | 22 class GURL; |
| 23 | 23 |
| 24 namespace domain_reliability { | 24 namespace domain_reliability { |
| 25 | 25 |
| 26 class DomainReliabilityDispatcher; | 26 class DomainReliabilityDispatcher; |
| 27 class MockableTime; | 27 class MockableTime; |
| 28 | 28 |
| 29 // The per-domain context for the Domain Reliability client; includes the | 29 // The per-domain context for the Domain Reliability client; includes the |
| 30 // domain's config and per-resource beacon queues. | 30 // domain's config and per-resource beacon queues. |
| 31 class DOMAIN_RELIABILITY_EXPORT DomainReliabilityContext { | 31 class DOMAIN_RELIABILITY_EXPORT DomainReliabilityContext { |
| 32 public: | 32 public: |
| 33 DomainReliabilityContext( | 33 DomainReliabilityContext( |
| 34 MockableTime* time, | 34 MockableTime* time, |
|
Ryan Sleevi
2014/04/25 01:00:02
nit: Should "MockableTime" be called what it is, r
Deprecated (see juliatuttle)
2014/04/28 22:01:13
Yeah, we might be able to come up with a nicer nam
| |
| 35 const DomainReliabilityScheduler::Params& scheduler_params, | 35 const DomainReliabilityScheduler::Params& scheduler_params, |
| 36 DomainReliabilityDispatcher* dispatcher, | 36 DomainReliabilityDispatcher* dispatcher, |
| 37 DomainReliabilityUploader* uploader, | 37 DomainReliabilityUploader* uploader, |
| 38 scoped_ptr<const DomainReliabilityConfig> config); | 38 scoped_ptr<const DomainReliabilityConfig> config); |
| 39 virtual ~DomainReliabilityContext(); | 39 virtual ~DomainReliabilityContext(); |
|
Ryan Sleevi
2014/04/25 01:00:02
Why is this virtual, when you have no virtual meth
Deprecated (see juliatuttle)
2014/04/28 22:01:13
Done.
| |
| 40 | 40 |
| 41 // Adds a beacon; may or may not save the actual beacon to be uploaded, | |
| 42 // depending on the sample rates in the config, but will increment one of | |
| 43 // the request counters in any case. | |
|
Ryan Sleevi
2014/04/25 01:00:02
Should this be called "RegisterBeacon" instead? Or
Deprecated (see juliatuttle)
2014/04/28 22:01:13
Yeah, I've never been happy with this name. I thin
| |
| 41 void AddBeacon(const DomainReliabilityBeacon& beacon, const GURL& url); | 44 void AddBeacon(const DomainReliabilityBeacon& beacon, const GURL& url); |
| 42 | 45 |
| 43 void GetQueuedDataForTesting( | 46 void GetQueuedDataForTesting( |
| 44 int resource_index, | 47 int resource_index, |
| 45 std::vector<DomainReliabilityBeacon>* beacons_out, | 48 std::vector<DomainReliabilityBeacon>* beacons_out, |
| 46 int* successful_requests_out, | 49 int* successful_requests_out, |
| 47 int* failed_requests_out) const; | 50 int* failed_requests_out) const; |
|
Ryan Sleevi
2014/04/25 01:00:02
For "counts of things" and indices, use unsigned i
Deprecated (see juliatuttle)
2014/04/28 22:01:13
Done.
| |
| 48 | 51 |
| 49 const DomainReliabilityConfig& config() { return *config_.get(); } | 52 const DomainReliabilityConfig& config() { return *config_.get(); } |
| 50 | 53 |
| 51 // Maximum number of beacons queued per context; if more than this many are | 54 // Maximum number of beacons queued per context; if more than this many are |
| 52 // queued; the oldest beacons will be removed. | 55 // queued; the oldest beacons will be removed. |
| 53 static const int kMaxQueuedBeacons; | 56 static const int kMaxQueuedBeacons; |
|
Ryan Sleevi
2014/04/25 01:00:02
For "counts of things", use unsigned integer types
Deprecated (see juliatuttle)
2014/04/28 22:01:13
Done.
| |
| 54 | 57 |
| 55 private: | 58 private: |
| 56 // Resource-specific state (queued beacons and request counts). | 59 // Resource-specific state (queued beacons and request counts). |
| 57 class ResourceState { | 60 class ResourceState { |
|
Ryan Sleevi
2014/04/25 01:00:02
Because you the ScopedVector<> isn't instantiated
Deprecated (see juliatuttle)
2014/04/28 22:01:13
Done.
| |
| 58 public: | 61 public: |
| 59 ResourceState(DomainReliabilityContext* context, | 62 ResourceState(DomainReliabilityContext* context, |
| 60 const DomainReliabilityConfig::Resource* config); | 63 const DomainReliabilityConfig::Resource* config); |
| 61 ~ResourceState(); | 64 ~ResourceState(); |
| 62 | 65 |
| 63 scoped_ptr<base::Value> ToValue(base::TimeTicks upload_time) const; | 66 scoped_ptr<base::Value> ToValue(base::TimeTicks upload_time) const; |
| 64 | 67 |
| 65 // Remembers the current state of the resource data when an upload starts. | 68 // Remembers the current state of the resource data when an upload starts. |
| 66 void MarkUpload(); | 69 void MarkUpload(); |
| 67 | 70 |
| 68 // Uses the state remembered by |MarkUpload| to remove successfully uploaded | 71 // Uses the state remembered by |MarkUpload| to remove successfully uploaded |
| 69 // data but keep beacons and request counts added after the upload started. | 72 // data but keep beacons and request counts added after the upload started. |
| 70 void CommitUpload(); | 73 void CommitUpload(); |
| 71 | 74 |
| 72 // Gets the start time of the oldest beacon, if there are any. Returns true | 75 // Gets the start time of the oldest beacon, if there are any. Returns true |
| 73 // and sets |oldest_start_out| if so; otherwise, returns false. | 76 // and sets |oldest_start_out| if so; otherwise, returns false. |
| 74 bool GetOldestBeaconStart(base::TimeTicks* oldest_start_out) const; | 77 bool GetOldestBeaconStart(base::TimeTicks* oldest_start_out) const; |
| 75 // Removes the oldest beacon. DCHECKs if there isn't one. | 78 // Removes the oldest beacon. DCHECKs if there isn't one. |
|
Ryan Sleevi
2014/04/25 01:00:02
nit: newline between 77/78.
Deprecated (see juliatuttle)
2014/04/28 22:01:13
Done.
| |
| 76 void RemoveOldestBeacon(); | 79 void RemoveOldestBeacon(); |
| 77 | 80 |
| 78 DomainReliabilityContext* context; | 81 DomainReliabilityContext* context; |
| 79 const DomainReliabilityConfig::Resource* config; | 82 const DomainReliabilityConfig::Resource* config; |
| 80 | 83 |
| 81 std::deque<DomainReliabilityBeacon> beacons; | 84 std::deque<DomainReliabilityBeacon> beacons; |
| 82 int successful_requests; | 85 int successful_requests; |
| 83 int failed_requests; | 86 int failed_requests; |
| 84 | 87 |
| 85 // State saved during uploads; if an upload succeeds, these are used to | 88 // State saved during uploads; if an upload succeeds, these are used to |
| 86 // remove uploaded data from the beacon list and request counters. | 89 // remove uploaded data from the beacon list and request counters. |
| 87 size_t uploading_beacons_size; | 90 size_t uploading_beacons_size; |
| 88 int uploading_successful_requests; | 91 int uploading_successful_requests; |
| 89 int uploading_failed_requests; | 92 int uploading_failed_requests; |
|
Ryan Sleevi
2014/04/25 01:00:02
size_t for 85, 86, 91, 92
Deprecated (see juliatuttle)
2014/04/28 22:01:13
Done.
| |
| 90 | 93 |
| 91 private: | 94 private: |
| 92 DISALLOW_COPY_AND_ASSIGN(ResourceState); | 95 DISALLOW_COPY_AND_ASSIGN(ResourceState); |
| 93 }; | 96 }; |
| 94 | 97 |
| 95 typedef ScopedVector<ResourceState> ResourceStateVector; | 98 typedef ScopedVector<ResourceState> ResourceStateVector; |
| 96 typedef ResourceStateVector::const_iterator ResourceStateIterator; | 99 typedef ResourceStateVector::const_iterator ResourceStateIterator; |
| 97 | 100 |
| 98 void InitializeResourceStates(); | 101 void InitializeResourceStates(); |
| 99 void ScheduleUpload(base::TimeDelta min_delay, base::TimeDelta max_delay); | 102 void ScheduleUpload(base::TimeDelta min_delay, base::TimeDelta max_delay); |
| 100 void StartUpload(); | 103 void StartUpload(); |
| 101 void OnUploadComplete(bool success); | 104 void OnUploadComplete(bool success); |
| 102 | 105 |
| 103 scoped_ptr<const base::Value> CreateReport(base::TimeTicks upload_time) const; | 106 scoped_ptr<const base::Value> CreateReport(base::TimeTicks upload_time) const; |
| 104 | 107 |
| 105 // Remembers the current state of the context when an upload starts. | 108 // Remembers the current state of the context when an upload starts. |
| 106 void MarkUpload(); | 109 void MarkUpload(); |
| 107 | 110 |
| 108 // Uses the state remembered by |MarkUpload| to remove successfully uploaded | 111 // Uses the state remembered by |MarkUpload| to remove successfully uploaded |
| 109 // data but keep beacons and request counts added after the upload started. | 112 // data but keep beacons and request counts added after the upload started. |
| 110 void CommitUpload(); | 113 void CommitUpload(); |
| 111 | 114 |
| 112 // Finds and removes the oldest beacon. DCHECKs if there is none. (Called | 115 // Finds and removes the oldest beacon. DCHECKs if there is none. (Called |
| 113 // when there are too many beacons queued.) | 116 // when there are too many beacons queued.) |
| 114 void RemoveOldestBeacon(); | 117 void RemoveOldestBeacon(); |
|
Ryan Sleevi
2014/04/25 01:00:02
I find it weird to see 108-117 duplicated with eff
Deprecated (see juliatuttle)
2014/04/28 22:01:13
If you want, I can just have Context::MarkUpload m
| |
| 115 | 118 |
| 116 scoped_ptr<const DomainReliabilityConfig> config_; | 119 scoped_ptr<const DomainReliabilityConfig> config_; |
| 117 MockableTime* time_; | 120 MockableTime* time_; |
| 118 DomainReliabilityScheduler scheduler_; | 121 DomainReliabilityScheduler scheduler_; |
| 119 DomainReliabilityDispatcher* dispatcher_; | 122 DomainReliabilityDispatcher* dispatcher_; |
| 120 DomainReliabilityUploader* uploader_; | 123 DomainReliabilityUploader* uploader_; |
| 121 | 124 |
| 122 // Each ResourceState in |states_| corresponds to the Resource of the same | 125 // Each ResourceState in |states_| corresponds to the Resource of the same |
| 123 // index in the config. | 126 // index in the config. |
| 124 ResourceStateVector states_; | 127 ResourceStateVector states_; |
| 125 int beacon_count_; | 128 int beacon_count_; |
| 126 int uploading_beacon_count_; | 129 int uploading_beacon_count_; |
|
Ryan Sleevi
2014/04/25 01:00:02
size_t for counts
Deprecated (see juliatuttle)
2014/04/28 22:01:13
Done.
| |
| 127 base::TimeTicks upload_time_; | 130 base::TimeTicks upload_time_; |
| 128 base::TimeTicks last_upload_time_; | 131 base::TimeTicks last_upload_time_; |
| 129 | 132 |
| 130 base::WeakPtrFactory<DomainReliabilityContext> weak_factory_; | 133 base::WeakPtrFactory<DomainReliabilityContext> weak_factory_; |
| 131 | 134 |
| 132 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityContext); | 135 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityContext); |
| 133 }; | 136 }; |
| 134 | 137 |
| 135 } // namespace domain_reliability | 138 } // namespace domain_reliability |
| 136 | 139 |
| 137 #endif // COMPONENTS_DOMAIN_RELIABILITY_CONTEXT_H_ | 140 #endif // COMPONENTS_DOMAIN_RELIABILITY_CONTEXT_H_ |
| OLD | NEW |