OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/metrics/variations/variations_http_header_provider.h" | 5 #include "chrome/browser/metrics/variations/variations_http_header_provider.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
| 9 #include "base/metrics/histogram.h" |
9 #include "chrome/browser/google/google_util.h" | 10 #include "chrome/browser/google/google_util.h" |
10 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/profiles/profile_io_data.h" | 12 #include "chrome/browser/profiles/profile_io_data.h" |
12 #include "chrome/common/metrics/proto/chrome_experiments.pb.h" | 13 #include "chrome/common/metrics/proto/chrome_experiments.pb.h" |
13 #include "chrome/common/metrics/variations/variations_util.h" | 14 #include "chrome/common/metrics/variations/variations_util.h" |
14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
15 #include "net/http/http_request_headers.h" | 16 #include "net/http/http_request_headers.h" |
16 | 17 |
17 using content::BrowserThread; | 18 using content::BrowserThread; |
18 | 19 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 void VariationsHttpHeaderProvider::InitVariationIDsCacheIfNeeded() { | 86 void VariationsHttpHeaderProvider::InitVariationIDsCacheIfNeeded() { |
86 base::AutoLock scoped_lock(lock_); | 87 base::AutoLock scoped_lock(lock_); |
87 if (variation_ids_cache_initialized_) | 88 if (variation_ids_cache_initialized_) |
88 return; | 89 return; |
89 | 90 |
90 // Register for additional cache updates. This is done first to avoid a race | 91 // Register for additional cache updates. This is done first to avoid a race |
91 // that could cause registered FieldTrials to be missed. | 92 // that could cause registered FieldTrials to be missed. |
92 DCHECK(MessageLoop::current()); | 93 DCHECK(MessageLoop::current()); |
93 base::FieldTrialList::AddObserver(this); | 94 base::FieldTrialList::AddObserver(this); |
94 | 95 |
| 96 base::TimeTicks before_time = base::TimeTicks::Now(); |
| 97 |
95 base::FieldTrial::ActiveGroups initial_groups; | 98 base::FieldTrial::ActiveGroups initial_groups; |
96 base::FieldTrialList::GetActiveFieldTrialGroups(&initial_groups); | 99 base::FieldTrialList::GetActiveFieldTrialGroups(&initial_groups); |
97 for (base::FieldTrial::ActiveGroups::const_iterator it = | 100 for (base::FieldTrial::ActiveGroups::const_iterator it = |
98 initial_groups.begin(); | 101 initial_groups.begin(); |
99 it != initial_groups.end(); ++it) { | 102 it != initial_groups.end(); ++it) { |
100 const VariationID id = | 103 const VariationID id = |
101 GetGoogleVariationID(GOOGLE_WEB_PROPERTIES, it->trial_name, | 104 GetGoogleVariationID(GOOGLE_WEB_PROPERTIES, it->trial_name, |
102 it->group_name); | 105 it->group_name); |
103 if (id != EMPTY_ID) | 106 if (id != EMPTY_ID) |
104 variation_ids_set_.insert(id); | 107 variation_ids_set_.insert(id); |
105 } | 108 } |
106 UpdateVariationIDsHeaderValue(); | 109 UpdateVariationIDsHeaderValue(); |
107 | 110 |
| 111 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 112 "Variations.HeaderConstructionTime", |
| 113 (base::TimeTicks::Now() - before_time).InMicroseconds(), |
| 114 0, |
| 115 base::TimeDelta::FromSeconds(1).InMicroseconds(), |
| 116 50); |
| 117 |
108 variation_ids_cache_initialized_ = true; | 118 variation_ids_cache_initialized_ = true; |
109 } | 119 } |
110 | 120 |
111 void VariationsHttpHeaderProvider::UpdateVariationIDsHeaderValue() { | 121 void VariationsHttpHeaderProvider::UpdateVariationIDsHeaderValue() { |
112 lock_.AssertAcquired(); | 122 lock_.AssertAcquired(); |
113 | 123 |
114 // The header value is a serialized protobuffer of Variation IDs which is | 124 // The header value is a serialized protobuffer of Variation IDs which is |
115 // base64 encoded before transmitting as a string. | 125 // base64 encoded before transmitting as a string. |
116 if (variation_ids_set_.empty()) | 126 if (variation_ids_set_.empty()) |
117 return; | 127 return; |
(...skipping 23 matching lines...) Expand all Loading... |
141 // if IDs are added as the header is recreated. The receiving servers are OK | 151 // if IDs are added as the header is recreated. The receiving servers are OK |
142 // with such descrepancies. | 152 // with such descrepancies. |
143 variation_ids_header_ = hashed; | 153 variation_ids_header_ = hashed; |
144 } else { | 154 } else { |
145 NOTREACHED() << "Failed to base64 encode Variation IDs value: " | 155 NOTREACHED() << "Failed to base64 encode Variation IDs value: " |
146 << serialized; | 156 << serialized; |
147 } | 157 } |
148 } | 158 } |
149 | 159 |
150 } // namespace chrome_variations | 160 } // namespace chrome_variations |
OLD | NEW |