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

Side by Side Diff: Source/core/frame/UseByOriginCounter.cpp

Issue 986583002: Collect host of Web Component usage to send to RAPPOR (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 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
« no previous file with comments | « Source/core/frame/UseByOriginCounter.h ('k') | Source/core/frame/UseCounter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
bashi 2015/03/09 23:42:31 nit: Use the 3-line license header.
kojii 2015/03/10 05:06:16 Done, thank you, I missed that.
2 * Copyright (C) 2015 Google, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "config.h"
27 #include "core/frame/UseByOriginCounter.h"
28
29 #include "bindings/core/v8/ScriptState.h"
30 #include "core/dom/Document.h"
31 #include "core/dom/ExecutionContext.h"
32 #include "core/frame/UseCounter.h"
33
34 namespace blink {
35
36 UseByOriginCounter::Value::Value()
37 : m_countBits(0)
38 {
39 }
40
41 void UseByOriginCounter::count(const ScriptState* scriptState, Document& documen t, Feature feature)
42 {
43 if (!scriptState || !scriptState->world().isMainWorld())
44 return;
45 document.useByOriginCounterValue().count(feature);
46 }
47
48 void UseByOriginCounter::Value::count(Feature feature)
49 {
50 ASSERT((unsigned)feature >= 0 && feature < Feature::NumberOfFeatures);
51 m_countBits |= 1 << (unsigned)feature;
52 }
53
54 void UseByOriginCounter::documentDetached(Document& document)
55 {
56 UseByOriginCounter::Value counter = document.useByOriginCounterValue();
57 if (counter.isEmpty())
58 return;
59 const KURL& url = document.url();
60 if (!url.protocolIsInHTTPFamily())
61 return;
62 m_originAndValues.append(std::make_pair(url.host(), counter));
63 document.useByOriginCounterValue().clear();
64 ASSERT(document.useByOriginCounterValue().isEmpty());
65 }
66
67 void UseByOriginCounter::updateMeasurementsAndClear()
68 {
69 if (m_originAndValues.isEmpty())
70 return;
71
72 // Aggregate values by origins.
73 HashMap<String, UseByOriginCounter::Value> aggregatedByOrigin;
74 for (std::pair<String, UseByOriginCounter::Value>& originAndValue : m_origin AndValues) {
75 ASSERT(!originAndValue.first.isEmpty());
76 auto result = aggregatedByOrigin.add(originAndValue.first, originAndValu e.second);
77 if (!result.isNewEntry)
78 result.storedValue->value.aggregate(originAndValue.second);
79 }
80
81 // FIXME: Reporting to RAPPOR is not implemented yet.
82 // for (auto& counter : aggregatedByOrigin) {
83 // }
84
85 m_originAndValues.clear();
86 }
87
88 void UseByOriginCounter::Value::aggregate(UseByOriginCounter::Value other)
89 {
90 m_countBits |= other.m_countBits;
91 }
92
93 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/frame/UseByOriginCounter.h ('k') | Source/core/frame/UseCounter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698