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

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/private_api_misc.cc

Issue 520623002: Remove Files.app's own profile badge. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 6 years, 3 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 | « no previous file | chrome/browser/chromeos/file_manager/file_manager_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 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/chromeos/extensions/file_manager/private_api_misc.h" 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_misc.h"
6 6
7 #include "ash/frame/frame_util.h" 7 #include "ash/frame/frame_util.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 AppWindowRegistry::Get(function->GetProfile()); 55 AppWindowRegistry::Get(function->GetProfile());
56 content::WebContents* const contents = function->GetAssociatedWebContents(); 56 content::WebContents* const contents = function->GetAssociatedWebContents();
57 content::RenderViewHost* const render_view_host = 57 content::RenderViewHost* const render_view_host =
58 contents ? contents->GetRenderViewHost() : NULL; 58 contents ? contents->GetRenderViewHost() : NULL;
59 return render_view_host ? app_window_registry->GetAppWindowForRenderViewHost( 59 return render_view_host ? app_window_registry->GetAppWindowForRenderViewHost(
60 render_view_host) 60 render_view_host)
61 : NULL; 61 : NULL;
62 } 62 }
63 63
64 std::vector<linked_ptr<api::file_browser_private::ProfileInfo> > 64 std::vector<linked_ptr<api::file_browser_private::ProfileInfo> >
65 GetLoggedInProfileInfoList(content::WebContents* contents) { 65 GetLoggedInProfileInfoList() {
66 DCHECK(user_manager::UserManager::IsInitialized()); 66 DCHECK(user_manager::UserManager::IsInitialized());
67 const std::vector<Profile*>& profiles = 67 const std::vector<Profile*>& profiles =
68 g_browser_process->profile_manager()->GetLoadedProfiles(); 68 g_browser_process->profile_manager()->GetLoadedProfiles();
69 std::set<Profile*> original_profiles; 69 std::set<Profile*> original_profiles;
70 std::vector<linked_ptr<api::file_browser_private::ProfileInfo> > 70 std::vector<linked_ptr<api::file_browser_private::ProfileInfo> >
71 result_profiles; 71 result_profiles;
72 72
73 for (size_t i = 0; i < profiles.size(); ++i) { 73 for (size_t i = 0; i < profiles.size(); ++i) {
74 // Filter the profile. 74 // Filter the profile.
75 Profile* const profile = profiles[i]->GetOriginalProfile(); 75 Profile* const profile = profiles[i]->GetOriginalProfile();
76 if (original_profiles.count(profile)) 76 if (original_profiles.count(profile))
77 continue; 77 continue;
78 original_profiles.insert(profile); 78 original_profiles.insert(profile);
79 const user_manager::User* const user = 79 const user_manager::User* const user =
80 chromeos::ProfileHelper::Get()->GetUserByProfile(profile); 80 chromeos::ProfileHelper::Get()->GetUserByProfile(profile);
81 if (!user || !user->is_logged_in()) 81 if (!user || !user->is_logged_in())
82 continue; 82 continue;
83 83
84 // Make a ProfileInfo. 84 // Make a ProfileInfo.
85 linked_ptr<api::file_browser_private::ProfileInfo> profile_info( 85 linked_ptr<api::file_browser_private::ProfileInfo> profile_info(
86 new api::file_browser_private::ProfileInfo()); 86 new api::file_browser_private::ProfileInfo());
87 profile_info->profile_id = multi_user_util::GetUserIDFromProfile(profile); 87 profile_info->profile_id = multi_user_util::GetUserIDFromProfile(profile);
88 profile_info->display_name = UTF16ToUTF8(user->GetDisplayName()); 88 profile_info->display_name = UTF16ToUTF8(user->GetDisplayName());
89 // TODO(hirono): Remove the property from the profile_info. 89 // TODO(hirono): Remove the property from the profile_info.
90 profile_info->is_current_profile = true; 90 profile_info->is_current_profile = true;
91 91
92 // Make an icon URL of the profile.
93 if (contents) {
94 const gfx::Image& image =
95 ash::GetAvatarImageForContext(contents->GetBrowserContext());
96 const gfx::ImageSkia& skia = image.AsImageSkia();
97 profile_info->profile_image.reset(
98 new api::file_browser_private::ImageSet);
99 profile_info->profile_image->scale1x_url =
100 webui::GetBitmapDataUrl(skia.GetRepresentation(1.0f).sk_bitmap());
101 profile_info->profile_image->scale2x_url =
102 webui::GetBitmapDataUrl(skia.GetRepresentation(2.0f).sk_bitmap());
103 }
104 result_profiles.push_back(profile_info); 92 result_profiles.push_back(profile_info);
105 } 93 }
106 94
107 return result_profiles; 95 return result_profiles;
108 } 96 }
109 } // namespace 97 } // namespace
110 98
111 bool FileBrowserPrivateLogoutUserForReauthenticationFunction::RunSync() { 99 bool FileBrowserPrivateLogoutUserForReauthenticationFunction::RunSync() {
112 user_manager::User* user = 100 user_manager::User* user =
113 chromeos::ProfileHelper::Get()->GetUserByProfile(GetProfile()); 101 chromeos::ProfileHelper::Get()->GetUserByProfile(GetProfile());
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 "CWS OAuth token fetch failed. (GDataErrorCode: %s)", 361 "CWS OAuth token fetch failed. (GDataErrorCode: %s)",
374 google_apis::GDataErrorCodeToString(code).c_str()); 362 google_apis::GDataErrorCodeToString(code).c_str());
375 } 363 }
376 SetResult(base::Value::CreateNullValue()); 364 SetResult(base::Value::CreateNullValue());
377 SendResponse(false); 365 SendResponse(false);
378 } 366 }
379 } 367 }
380 368
381 bool FileBrowserPrivateGetProfilesFunction::RunSync() { 369 bool FileBrowserPrivateGetProfilesFunction::RunSync() {
382 const std::vector<linked_ptr<api::file_browser_private::ProfileInfo> >& 370 const std::vector<linked_ptr<api::file_browser_private::ProfileInfo> >&
383 profiles = GetLoggedInProfileInfoList(GetAssociatedWebContents()); 371 profiles = GetLoggedInProfileInfoList();
384 372
385 // Obtains the display profile ID. 373 // Obtains the display profile ID.
386 AppWindow* const app_window = GetCurrentAppWindow(this); 374 AppWindow* const app_window = GetCurrentAppWindow(this);
387 chrome::MultiUserWindowManager* const window_manager = 375 chrome::MultiUserWindowManager* const window_manager =
388 chrome::MultiUserWindowManager::GetInstance(); 376 chrome::MultiUserWindowManager::GetInstance();
389 const std::string current_profile_id = 377 const std::string current_profile_id =
390 multi_user_util::GetUserIDFromProfile(GetProfile()); 378 multi_user_util::GetUserIDFromProfile(GetProfile());
391 const std::string display_profile_id = 379 const std::string display_profile_id =
392 window_manager && app_window ? window_manager->GetUserPresentingWindow( 380 window_manager && app_window ? window_manager->GetUserPresentingWindow(
393 app_window->GetNativeWindow()) 381 app_window->GetNativeWindow())
394 : ""; 382 : "";
395 383
396 results_ = api::file_browser_private::GetProfiles::Results::Create( 384 results_ = api::file_browser_private::GetProfiles::Results::Create(
397 profiles, 385 profiles,
398 current_profile_id, 386 current_profile_id,
399 display_profile_id.empty() ? current_profile_id : display_profile_id); 387 display_profile_id.empty() ? current_profile_id : display_profile_id);
400 return true; 388 return true;
401 } 389 }
402 390
403 bool FileBrowserPrivateVisitDesktopFunction::RunSync() { 391 bool FileBrowserPrivateVisitDesktopFunction::RunSync() {
404 using api::file_browser_private::VisitDesktop::Params; 392 using api::file_browser_private::VisitDesktop::Params;
405 const scoped_ptr<Params> params(Params::Create(*args_)); 393 const scoped_ptr<Params> params(Params::Create(*args_));
406 const std::vector<linked_ptr<api::file_browser_private::ProfileInfo> >& 394 const std::vector<linked_ptr<api::file_browser_private::ProfileInfo> >&
407 profiles = GetLoggedInProfileInfoList(GetAssociatedWebContents()); 395 profiles = GetLoggedInProfileInfoList();
408 396
409 chrome::MultiUserWindowManager* const window_manager = 397 chrome::MultiUserWindowManager* const window_manager =
410 chrome::MultiUserWindowManager::GetInstance(); 398 chrome::MultiUserWindowManager::GetInstance();
411 DCHECK(window_manager); 399 DCHECK(window_manager);
412 400
413 // Check if the target user is logged-in or not. 401 // Check if the target user is logged-in or not.
414 bool logged_in = false; 402 bool logged_in = false;
415 for (size_t i = 0; i < profiles.size(); ++i) { 403 for (size_t i = 0; i < profiles.size(); ++i) {
416 if (profiles[i]->profile_id == params->profile_id) { 404 if (profiles[i]->profile_id == params->profile_id) {
417 logged_in = true; 405 logged_in = true;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 NOTREACHED(); 469 NOTREACHED();
482 SetError( 470 SetError(
483 base::StringPrintf("Unexpected inspection type(%d) is specified.", 471 base::StringPrintf("Unexpected inspection type(%d) is specified.",
484 static_cast<int>(params->type))); 472 static_cast<int>(params->type)));
485 return false; 473 return false;
486 } 474 }
487 return true; 475 return true;
488 } 476 }
489 477
490 } // namespace extensions 478 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/file_manager/file_manager_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698