Chromium Code Reviews| 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/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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 380 } | 380 } |
| 381 | 381 |
| 382 ExtensionIdList::const_iterator pos = | 382 ExtensionIdList::const_iterator pos = |
| 383 std::find(positions.begin(), positions.end(), extension->id()); | 383 std::find(positions.begin(), positions.end(), extension->id()); |
| 384 if (pos != positions.end()) | 384 if (pos != positions.end()) |
| 385 sorted[pos - positions.begin()] = extension; | 385 sorted[pos - positions.begin()] = extension; |
| 386 else | 386 else |
| 387 unsorted.push_back(make_scoped_refptr(extension)); | 387 unsorted.push_back(make_scoped_refptr(extension)); |
| 388 } | 388 } |
| 389 | 389 |
| 390 // Erase current icons. | 390 size_t items_count = toolbar_items_.size(); |
| 391 for (size_t i = 0; i < toolbar_items_.size(); i++) { | 391 for (size_t i = 0; i < items_count; i++) { |
| 392 const Extension* extension = toolbar_items_.back(); | |
| 393 toolbar_items_.pop_back(); | |
|
Finnur
2014/05/23 16:30:44
By popping the extension here (before calling Brow
Devlin
2014/05/23 17:18:26
Good comment. Such a good comment, it should prob
| |
| 392 FOR_EACH_OBSERVER( | 394 FOR_EACH_OBSERVER( |
| 393 Observer, observers_, BrowserActionRemoved(toolbar_items_[i].get())); | 395 Observer, observers_, BrowserActionRemoved(extension)); |
| 394 } | 396 } |
| 395 toolbar_items_.clear(); | 397 DCHECK(toolbar_items_.empty()); |
| 396 | 398 |
| 397 // Merge the lists. | 399 // Merge the lists. |
| 398 toolbar_items_.reserve(sorted.size() + unsorted.size()); | 400 toolbar_items_.reserve(sorted.size() + unsorted.size()); |
| 401 | |
| 402 int count = 0; | |
|
Devlin
2014/05/23 17:18:26
I wonder if this is worth keeping, even. Isn't co
| |
| 399 for (ExtensionList::const_iterator iter = sorted.begin(); | 403 for (ExtensionList::const_iterator iter = sorted.begin(); |
| 400 iter != sorted.end(); ++iter) { | 404 iter != sorted.end(); ++iter) { |
|
Devlin
2014/05/23 17:18:26
nit: I think the "four-space line continuation" ru
| |
| 401 // It's possible for the extension order to contain items that aren't | 405 // It's possible for the extension order to contain items that aren't |
| 402 // actually loaded on this machine. For example, when extension sync is on, | 406 // actually loaded on this machine. For example, when extension sync is on, |
| 403 // we sync the extension order as-is but double-check with the user before | 407 // we sync the extension order as-is but double-check with the user before |
| 404 // syncing NPAPI-containing extensions, so if one of those is not actually | 408 // syncing NPAPI-containing extensions, so if one of those is not actually |
| 405 // synced, we'll get a NULL in the list. This sort of case can also happen | 409 // synced, we'll get a NULL in the list. This sort of case can also happen |
| 406 // if some error prevents an extension from loading. | 410 // if some error prevents an extension from loading. |
| 407 if (iter->get() != NULL) | 411 if (iter->get() != NULL) { |
| 408 toolbar_items_.push_back(*iter); | 412 toolbar_items_.push_back(*iter); |
| 413 FOR_EACH_OBSERVER( | |
| 414 Observer, observers_, BrowserActionAdded(*iter, count)); | |
| 415 count++; | |
|
Devlin
2014/05/23 17:18:26
nit: ++count in chromium, unless there's a specifi
| |
| 416 } | |
| 409 } | 417 } |
| 410 toolbar_items_.insert(toolbar_items_.end(), unsorted.begin(), | 418 for (ExtensionList::const_iterator iter = unsorted.begin(); |
| 411 unsorted.end()); | 419 iter != unsorted.end(); ++iter) { |
| 420 if (iter->get() != NULL) { | |
| 421 toolbar_items_.push_back(*iter); | |
| 422 FOR_EACH_OBSERVER( | |
| 423 Observer, observers_, BrowserActionAdded(*iter, count)); | |
| 424 count++; | |
| 425 } | |
| 426 } | |
| 412 | 427 |
| 413 UMA_HISTOGRAM_COUNTS_100( | 428 UMA_HISTOGRAM_COUNTS_100( |
| 414 "ExtensionToolbarModel.BrowserActionsPermanentlyHidden", hidden); | 429 "ExtensionToolbarModel.BrowserActionsPermanentlyHidden", hidden); |
| 415 UMA_HISTOGRAM_COUNTS_100("ExtensionToolbarModel.BrowserActionsCount", | 430 UMA_HISTOGRAM_COUNTS_100("ExtensionToolbarModel.BrowserActionsCount", |
| 416 toolbar_items_.size()); | 431 toolbar_items_.size()); |
| 417 | 432 |
| 418 if (!toolbar_items_.empty()) { | 433 if (!toolbar_items_.empty()) { |
| 419 // Visible count can be -1, meaning: 'show all'. Since UMA converts negative | 434 // Visible count can be -1, meaning: 'show all'. Since UMA converts negative |
| 420 // values to 0, this would be counted as 'show none' unless we convert it to | 435 // values to 0, this would be counted as 'show none' unless we convert it to |
| 421 // max. | 436 // max. |
| 422 UMA_HISTOGRAM_COUNTS_100("ExtensionToolbarModel.BrowserActionsVisible", | 437 UMA_HISTOGRAM_COUNTS_100("ExtensionToolbarModel.BrowserActionsVisible", |
| 423 visible_icon_count_ == -1 ? | 438 visible_icon_count_ == -1 ? |
| 424 base::HistogramBase::kSampleType_MAX : | 439 base::HistogramBase::kSampleType_MAX : |
| 425 visible_icon_count_); | 440 visible_icon_count_); |
| 426 } | 441 } |
| 427 | |
| 428 // Inform observers. | |
| 429 for (size_t i = 0; i < toolbar_items_.size(); i++) { | |
| 430 FOR_EACH_OBSERVER( | |
| 431 Observer, observers_, BrowserActionAdded(toolbar_items_[i].get(), i)); | |
| 432 } | |
| 433 } | 442 } |
| 434 | 443 |
| 435 void ExtensionToolbarModel::UpdatePrefs() { | 444 void ExtensionToolbarModel::UpdatePrefs() { |
| 436 if (!extension_prefs_) | 445 if (!extension_prefs_) |
| 437 return; | 446 return; |
| 438 | 447 |
| 439 // Don't observe change caused by self. | 448 // Don't observe change caused by self. |
| 440 pref_change_registrar_.Remove(pref_names::kToolbar); | 449 pref_change_registrar_.Remove(pref_names::kToolbar); |
| 441 extension_prefs_->SetToolbarOrder(last_known_positions_); | 450 extension_prefs_->SetToolbarOrder(last_known_positions_); |
| 442 pref_change_registrar_.Add(pref_names::kToolbar, pref_change_callback_); | 451 pref_change_registrar_.Add(pref_names::kToolbar, pref_change_callback_); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 582 void ExtensionToolbarModel::StopHighlighting() { | 591 void ExtensionToolbarModel::StopHighlighting() { |
| 583 if (is_highlighting_) { | 592 if (is_highlighting_) { |
| 584 highlighted_items_.clear(); | 593 highlighted_items_.clear(); |
| 585 is_highlighting_ = false; | 594 is_highlighting_ = false; |
| 586 if (old_visible_icon_count_ != visible_icon_count_) { | 595 if (old_visible_icon_count_ != visible_icon_count_) { |
| 587 SetVisibleIconCount(old_visible_icon_count_); | 596 SetVisibleIconCount(old_visible_icon_count_); |
| 588 FOR_EACH_OBSERVER(Observer, observers_, VisibleCountChanged()); | 597 FOR_EACH_OBSERVER(Observer, observers_, VisibleCountChanged()); |
| 589 } | 598 } |
| 590 FOR_EACH_OBSERVER(Observer, observers_, HighlightModeChanged(false)); | 599 FOR_EACH_OBSERVER(Observer, observers_, HighlightModeChanged(false)); |
| 591 } | 600 } |
| 592 }; | 601 } |
| 593 | 602 |
| 594 } // namespace extensions | 603 } // namespace extensions |
| OLD | NEW |