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

Side by Side Diff: chrome/browser/extensions/extension_toolbar_model.cc

Issue 296983014: Fix issue with browser action toolbar putting all extension icons in overflow once sync happens. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Polish Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_toolbar_model_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/extensions/extension_toolbar_model.h" 5 #include "chrome/browser/extensions/extension_toolbar_model.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/metrics/histogram_base.h" 10 #include "base/metrics/histogram_base.h"
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 } 368 }
369 369
370 ExtensionIdList::const_iterator pos = 370 ExtensionIdList::const_iterator pos =
371 std::find(positions.begin(), positions.end(), extension->id()); 371 std::find(positions.begin(), positions.end(), extension->id());
372 if (pos != positions.end()) 372 if (pos != positions.end())
373 sorted[pos - positions.begin()] = extension; 373 sorted[pos - positions.begin()] = extension;
374 else 374 else
375 unsorted.push_back(make_scoped_refptr(extension)); 375 unsorted.push_back(make_scoped_refptr(extension));
376 } 376 }
377 377
378 // Erase current icons. 378 size_t items_count = toolbar_items_.size();
379 for (size_t i = 0; i < toolbar_items_.size(); i++) { 379 for (size_t i = 0; i < items_count; i++) {
380 const Extension* extension = toolbar_items_.back();
381 // By popping the extension here (before calling BrowserActionRemoved),
382 // we will not shrink visible count by one after BrowserActionRemoved
383 // calls SetVisibleCount.
384 toolbar_items_.pop_back();
380 FOR_EACH_OBSERVER( 385 FOR_EACH_OBSERVER(
381 Observer, observers_, BrowserActionRemoved(toolbar_items_[i].get())); 386 Observer, observers_, BrowserActionRemoved(extension));
382 } 387 }
383 toolbar_items_.clear(); 388 DCHECK(toolbar_items_.empty());
384 389
385 // Merge the lists. 390 // Merge the lists.
386 toolbar_items_.reserve(sorted.size() + unsorted.size()); 391 toolbar_items_.reserve(sorted.size() + unsorted.size());
392
387 for (ExtensionList::const_iterator iter = sorted.begin(); 393 for (ExtensionList::const_iterator iter = sorted.begin();
388 iter != sorted.end(); ++iter) { 394 iter != sorted.end(); ++iter) {
389 // It's possible for the extension order to contain items that aren't 395 // It's possible for the extension order to contain items that aren't
390 // actually loaded on this machine. For example, when extension sync is on, 396 // actually loaded on this machine. For example, when extension sync is on,
391 // we sync the extension order as-is but double-check with the user before 397 // we sync the extension order as-is but double-check with the user before
392 // syncing NPAPI-containing extensions, so if one of those is not actually 398 // syncing NPAPI-containing extensions, so if one of those is not actually
393 // synced, we'll get a NULL in the list. This sort of case can also happen 399 // synced, we'll get a NULL in the list. This sort of case can also happen
394 // if some error prevents an extension from loading. 400 // if some error prevents an extension from loading.
395 if (iter->get() != NULL) 401 if (iter->get() != NULL) {
396 toolbar_items_.push_back(*iter); 402 toolbar_items_.push_back(*iter);
403 FOR_EACH_OBSERVER(
404 Observer, observers_, BrowserActionAdded(
405 *iter, toolbar_items_.size() - 1));
406 }
397 } 407 }
398 toolbar_items_.insert(toolbar_items_.end(), unsorted.begin(), 408 for (ExtensionList::const_iterator iter = unsorted.begin();
399 unsorted.end()); 409 iter != unsorted.end(); ++iter) {
410 if (iter->get() != NULL) {
411 toolbar_items_.push_back(*iter);
412 FOR_EACH_OBSERVER(
413 Observer, observers_, BrowserActionAdded(
414 *iter, toolbar_items_.size() - 1));
415 }
416 }
400 417
401 UMA_HISTOGRAM_COUNTS_100( 418 UMA_HISTOGRAM_COUNTS_100(
402 "ExtensionToolbarModel.BrowserActionsPermanentlyHidden", hidden); 419 "ExtensionToolbarModel.BrowserActionsPermanentlyHidden", hidden);
403 UMA_HISTOGRAM_COUNTS_100("ExtensionToolbarModel.BrowserActionsCount", 420 UMA_HISTOGRAM_COUNTS_100("ExtensionToolbarModel.BrowserActionsCount",
404 toolbar_items_.size()); 421 toolbar_items_.size());
405 422
406 if (!toolbar_items_.empty()) { 423 if (!toolbar_items_.empty()) {
407 // Visible count can be -1, meaning: 'show all'. Since UMA converts negative 424 // Visible count can be -1, meaning: 'show all'. Since UMA converts negative
408 // values to 0, this would be counted as 'show none' unless we convert it to 425 // values to 0, this would be counted as 'show none' unless we convert it to
409 // max. 426 // max.
410 UMA_HISTOGRAM_COUNTS_100("ExtensionToolbarModel.BrowserActionsVisible", 427 UMA_HISTOGRAM_COUNTS_100("ExtensionToolbarModel.BrowserActionsVisible",
411 visible_icon_count_ == -1 ? 428 visible_icon_count_ == -1 ?
412 base::HistogramBase::kSampleType_MAX : 429 base::HistogramBase::kSampleType_MAX :
413 visible_icon_count_); 430 visible_icon_count_);
414 } 431 }
415
416 // Inform observers.
417 for (size_t i = 0; i < toolbar_items_.size(); i++) {
418 FOR_EACH_OBSERVER(
419 Observer, observers_, BrowserActionAdded(toolbar_items_[i].get(), i));
420 }
421 } 432 }
422 433
423 void ExtensionToolbarModel::UpdatePrefs() { 434 void ExtensionToolbarModel::UpdatePrefs() {
424 if (!extension_prefs_) 435 if (!extension_prefs_)
425 return; 436 return;
426 437
427 // Don't observe change caused by self. 438 // Don't observe change caused by self.
428 pref_change_registrar_.Remove(pref_names::kToolbar); 439 pref_change_registrar_.Remove(pref_names::kToolbar);
429 extension_prefs_->SetToolbarOrder(last_known_positions_); 440 extension_prefs_->SetToolbarOrder(last_known_positions_);
430 pref_change_registrar_.Add(pref_names::kToolbar, pref_change_callback_); 441 pref_change_registrar_.Add(pref_names::kToolbar, pref_change_callback_);
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 is_highlighting_ = false; 584 is_highlighting_ = false;
574 if (old_visible_icon_count_ != visible_icon_count_) { 585 if (old_visible_icon_count_ != visible_icon_count_) {
575 SetVisibleIconCount(old_visible_icon_count_); 586 SetVisibleIconCount(old_visible_icon_count_);
576 FOR_EACH_OBSERVER(Observer, observers_, VisibleCountChanged()); 587 FOR_EACH_OBSERVER(Observer, observers_, VisibleCountChanged());
577 } 588 }
578 FOR_EACH_OBSERVER(Observer, observers_, HighlightModeChanged(false)); 589 FOR_EACH_OBSERVER(Observer, observers_, HighlightModeChanged(false));
579 } 590 }
580 } 591 }
581 592
582 } // namespace extensions 593 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_toolbar_model_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698