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

Side by Side Diff: ui/base/clipboard/clipboard.cc

Issue 12313009: Add UMA statistics to the clipboard (Closed) Base URL: http://git.chromium.org/chromium/src.git@bug-177140-fix-test
Patch Set: Created 7 years, 10 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
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 "ui/base/clipboard/clipboard.h" 5 #include "ui/base/clipboard/clipboard.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/metrics/histogram.h"
12 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
13 #include "ui/gfx/size.h" 14 #include "ui/gfx/size.h"
14 15
15 namespace ui { 16 namespace ui {
16 17
17 namespace { 18 namespace {
18 19
19 // A compromised renderer could send us bad data, so validate it. 20 // A compromised renderer could send us bad data, so validate it.
20 // This function only checks that the size parameter makes sense, the caller 21 // This function only checks that the size parameter makes sense, the caller
21 // is responsible for further validating the bitmap buffer against 22 // is responsible for further validating the bitmap buffer against
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 97
97 // The union serves to easily convert SourceTag into its binary representation 98 // The union serves to easily convert SourceTag into its binary representation
98 // and vice versa. 99 // and vice versa.
99 union SourceTag2BinaryHelper { 100 union SourceTag2BinaryHelper {
100 Clipboard::SourceTag tag; 101 Clipboard::SourceTag tag;
101 uint8 bytes[kSourceTagSize]; 102 uint8 bytes[kSourceTagSize];
102 }; 103 };
103 104
104 } // namespace 105 } // namespace
105 106
107 const Clipboard::SourceTag Clipboard::kInvalidSourceTag =
108 reinterpret_cast<void*>(1);
106 const char Clipboard::kMimeTypeText[] = "text/plain"; 109 const char Clipboard::kMimeTypeText[] = "text/plain";
107 const char Clipboard::kMimeTypeURIList[] = "text/uri-list"; 110 const char Clipboard::kMimeTypeURIList[] = "text/uri-list";
108 const char Clipboard::kMimeTypeDownloadURL[] = "downloadurl"; 111 const char Clipboard::kMimeTypeDownloadURL[] = "downloadurl";
109 const char Clipboard::kMimeTypeHTML[] = "text/html"; 112 const char Clipboard::kMimeTypeHTML[] = "text/html";
110 const char Clipboard::kMimeTypeRTF[] = "text/rtf"; 113 const char Clipboard::kMimeTypeRTF[] = "text/rtf";
111 const char Clipboard::kMimeTypePNG[] = "image/png"; 114 const char Clipboard::kMimeTypePNG[] = "image/png";
112 115
113 // static 116 // static
114 Clipboard::ObjectMapParam Clipboard::SourceTag2Binary(SourceTag tag) { 117 Clipboard::ObjectMapParam Clipboard::SourceTag2Binary(SourceTag tag) {
115 SourceTag2BinaryHelper helper; 118 SourceTag2BinaryHelper helper;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 clipboard_map->erase(it); 182 clipboard_map->erase(it);
180 } 183 }
181 } 184 }
182 185
183 void Clipboard::WriteObjects(Buffer buffer, 186 void Clipboard::WriteObjects(Buffer buffer,
184 const ObjectMap& objects, 187 const ObjectMap& objects,
185 SourceTag tag) { 188 SourceTag tag) {
186 WriteObjectsImpl(buffer, objects, tag); 189 WriteObjectsImpl(buffer, objects, tag);
187 if (!write_objects_callback_.is_null()) 190 if (!write_objects_callback_.is_null())
188 write_objects_callback_.Run(buffer); 191 write_objects_callback_.Run(buffer);
192 ReportAction(buffer,
193 tag == SourceTag() ? WRITE_CLIPBOARD_NO_SOURCE_TAG :
tony 2013/02/20 19:25:07 Did you mean to wrap this line? I normally line u
vasilii 2013/02/21 10:36:01 Done.
194 WRITE_CLIPBOARD_SOURCE_TAG);
189 } 195 }
190 196
191 void Clipboard::DispatchObject(ObjectType type, const ObjectMapParams& params) { 197 void Clipboard::DispatchObject(ObjectType type, const ObjectMapParams& params) {
192 // All types apart from CBF_WEBKIT need at least 1 non-empty param. 198 // All types apart from CBF_WEBKIT need at least 1 non-empty param.
193 if (type != CBF_WEBKIT && (params.empty() || params[0].empty())) 199 if (type != CBF_WEBKIT && (params.empty() || params[0].empty()))
194 return; 200 return;
195 // Some other types need a non-empty 2nd param. 201 // Some other types need a non-empty 2nd param.
196 if ((type == CBF_BOOKMARK || type == CBF_BITMAP || 202 if ((type == CBF_BOOKMARK || type == CBF_BITMAP ||
197 type == CBF_SMBITMAP || type == CBF_DATA) && 203 type == CBF_SMBITMAP || type == CBF_DATA) &&
198 (params.size() != 2 || params[1].empty())) 204 (params.size() != 2 || params[1].empty()))
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 // We store the shared memory object pointer so it can be retrieved by the 298 // We store the shared memory object pointer so it can be retrieved by the
293 // UI thread (see DispatchObject()). 299 // UI thread (see DispatchObject()).
294 iter->second[0].clear(); 300 iter->second[0].clear();
295 for (size_t i = 0; i < sizeof(SharedMemory*); ++i) 301 for (size_t i = 0; i < sizeof(SharedMemory*); ++i)
296 iter->second[0].push_back(reinterpret_cast<char*>(&bitmap)[i]); 302 iter->second[0].push_back(reinterpret_cast<char*>(&bitmap)[i]);
297 has_shared_bitmap = true; 303 has_shared_bitmap = true;
298 } 304 }
299 } 305 }
300 } 306 }
301 307
308 void Clipboard::ReportAction(Buffer buffer, TrackedActions action) const
309 {
310 if (buffer != BUFFER_STANDARD)
311 return;
312
313 switch (action){
battre 2013/02/20 23:01:03 nit: space before {
vasilii 2013/02/21 10:36:01 Done.
314 case WRITE_CLIPBOARD_NO_SOURCE_TAG:
315 case WRITE_CLIPBOARD_SOURCE_TAG:
316 UMA_HISTOGRAM_ENUMERATION("Clipboard.Actions",
317 action,
318 MAX_TRACKED_ACTION);
319 break;
320 // The code below counts cases when there is the kInvalidSourceTag in the
321 // clipboard. That is, original data came from Incognito window and was
322 // destroyed with that window.
323 case READ_TEXT:
324 case READ_ASCII_TEXT:
325 case READ_RTF:
326 if (kInvalidSourceTag == ReadSourceTag(buffer)) {
327 UMA_HISTOGRAM_ENUMERATION("Clipboard.Actions",
battre 2013/02/20 23:01:03 The UMA name indicates that it records the number
vasilii 2013/02/21 10:36:01 Changed the name.
328 action,
329 MAX_TRACKED_ACTION);
330 }
331 break;
332 case MAX_TRACKED_ACTION:
333 break;
334 }
335 }
336
302 } // namespace ui 337 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698