| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/app_list/search/people/people_result.h" | 5 #include "chrome/browser/ui/app_list/search/people/people_result.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 14 #include "chrome/browser/signin/signin_manager_factory.h" | 14 #include "chrome/browser/signin/signin_manager_factory.h" |
| 15 #include "chrome/browser/ui/app_list/search/common/url_icon_source.h" | 15 #include "chrome/browser/ui/app_list/search/common/url_icon_source.h" |
| 16 #include "chrome/browser/ui/app_list/search/people/person.h" | 16 #include "chrome/browser/ui/app_list/search/people/person.h" |
| 17 #include "chrome/browser/ui/app_list/search/search_util.h" |
| 17 #include "chrome/browser/ui/browser_navigator.h" | 18 #include "chrome/browser/ui/browser_navigator.h" |
| 18 #include "chrome/common/extensions/api/hangouts_private.h" | 19 #include "chrome/common/extensions/api/hangouts_private.h" |
| 19 #include "chrome/grit/generated_resources.h" | 20 #include "chrome/grit/generated_resources.h" |
| 20 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 21 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 21 #include "components/signin/core/browser/signin_manager.h" | 22 #include "components/signin/core/browser/signin_manager.h" |
| 22 #include "content/public/browser/user_metrics.h" | 23 #include "content/public/browser/user_metrics.h" |
| 23 #include "extensions/browser/event_router.h" | 24 #include "extensions/browser/event_router.h" |
| 24 #include "grit/theme_resources.h" | 25 #include "grit/theme_resources.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 26 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 icon_size, | 80 icon_size, |
| 80 IDR_PROFILE_PICTURE_LOADING), | 81 IDR_PROFILE_PICTURE_LOADING), |
| 81 gfx::Size(icon_size, icon_size)); | 82 gfx::Size(icon_size, icon_size)); |
| 82 SetIcon(image_); | 83 SetIcon(image_); |
| 83 } | 84 } |
| 84 | 85 |
| 85 PeopleResult::~PeopleResult() { | 86 PeopleResult::~PeopleResult() { |
| 86 } | 87 } |
| 87 | 88 |
| 88 void PeopleResult::Open(int event_flags) { | 89 void PeopleResult::Open(int event_flags) { |
| 90 RecordHistogram(SEARCH_PEOPLE_SEARCH_RESULT); |
| 91 |
| 89 // Action 0 will always be our default action. | 92 // Action 0 will always be our default action. |
| 90 InvokeAction(0, event_flags); | 93 InvokeAction(0, event_flags); |
| 91 } | 94 } |
| 92 | 95 |
| 93 void PeopleResult::InvokeAction(int action_index, int event_flags) { | 96 void PeopleResult::InvokeAction(int action_index, int event_flags) { |
| 94 if (hangouts_extension_id_.empty()) { | 97 if (hangouts_extension_id_.empty()) { |
| 95 // If the hangouts app is not available, the only option we are showing | 98 // If the hangouts app is not available, the only option we are showing |
| 96 // to the user is 'Send Email'. | 99 // to the user is 'Send Email'. |
| 97 SendEmail(); | 100 SendEmail(); |
| 98 } else { | 101 } else { |
| 99 switch (action_index) { | 102 switch (action_index) { |
| 100 case 0: | 103 case 0: |
| 101 OpenChat(); | 104 OpenChat(); |
| 102 break; | 105 break; |
| 103 case 1: | 106 case 1: |
| 104 SendEmail(); | 107 SendEmail(); |
| 105 break; | 108 break; |
| 106 default: | 109 default: |
| 107 LOG(ERROR) << "Invalid people search action: " << action_index; | 110 LOG(ERROR) << "Invalid people search action: " << action_index; |
| 108 } | 111 } |
| 109 } | 112 } |
| 110 } | 113 } |
| 111 | 114 |
| 112 scoped_ptr<ChromeSearchResult> PeopleResult::Duplicate() { | 115 scoped_ptr<SearchResult> PeopleResult::Duplicate() { |
| 113 return scoped_ptr<ChromeSearchResult>( | 116 return scoped_ptr<SearchResult>( |
| 114 new PeopleResult(profile_, person_->Duplicate().Pass())).Pass(); | 117 new PeopleResult(profile_, person_->Duplicate().Pass())); |
| 115 } | 118 } |
| 116 | 119 |
| 117 void PeopleResult::OnIconLoaded() { | 120 void PeopleResult::OnIconLoaded() { |
| 118 // Remove the existing image reps since the icon data is loaded and they | 121 // Remove the existing image reps since the icon data is loaded and they |
| 119 // need to be re-created. | 122 // need to be re-created. |
| 120 const std::vector<gfx::ImageSkiaRep>& image_reps = image_.image_reps(); | 123 const std::vector<gfx::ImageSkiaRep>& image_reps = image_.image_reps(); |
| 121 for (size_t i = 0; i < image_reps.size(); ++i) | 124 for (size_t i = 0; i < image_reps.size(); ++i) |
| 122 image_.RemoveRepresentation(image_reps[i].scale()); | 125 image_.RemoveRepresentation(image_reps[i].scale()); |
| 123 | 126 |
| 124 SetIcon(image_); | 127 SetIcon(image_); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 for (size_t i = 0; i < arraysize(kHangoutsExtensionIds); ++i) { | 190 for (size_t i = 0; i < arraysize(kHangoutsExtensionIds); ++i) { |
| 188 if (extensions::EventRouter::Get(profile_)->ExtensionHasEventListener( | 191 if (extensions::EventRouter::Get(profile_)->ExtensionHasEventListener( |
| 189 kHangoutsExtensionIds[i], OnHangoutRequested::kEventName)) { | 192 kHangoutsExtensionIds[i], OnHangoutRequested::kEventName)) { |
| 190 hangouts_extension_id_ = kHangoutsExtensionIds[i]; | 193 hangouts_extension_id_ = kHangoutsExtensionIds[i]; |
| 191 return; | 194 return; |
| 192 } | 195 } |
| 193 } | 196 } |
| 194 hangouts_extension_id_.clear(); | 197 hangouts_extension_id_.clear(); |
| 195 } | 198 } |
| 196 | 199 |
| 197 ChromeSearchResultType PeopleResult::GetType() { | |
| 198 return SEARCH_PEOPLE_SEARCH_RESULT; | |
| 199 } | |
| 200 | |
| 201 } // namespace app_list | 200 } // namespace app_list |
| OLD | NEW |