Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/ash/launcher/chrome_mash_shelf_controller.h" | |
| 6 | |
| 7 #include "chrome/browser/profiles/profile_manager.h" | |
| 8 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" | |
| 9 #include "chrome/common/pref_names.h" | |
| 10 #include "chrome/grit/theme_resources.h" | |
| 11 #include "components/prefs/pref_service.h" | |
| 12 #include "content/public/common/mojo_shell_connection.h" | |
| 13 #include "mojo/shell/public/cpp/connector.h" | |
| 14 #include "skia/public/type_converters.h" | |
| 15 #include "ui/base/resource/resource_bundle.h" | |
| 16 | |
| 17 // static | |
| 18 ChromeMashShelfController* ChromeMashShelfController::instance_ = NULL; | |
|
James Cook
2016/04/06 04:29:52
drive-by nit: nullptr
msw
2016/04/07 20:34:57
Done.
| |
| 19 | |
| 20 ChromeMashShelfController::~ChromeMashShelfController() {} | |
| 21 | |
| 22 // static | |
| 23 ChromeMashShelfController* ChromeMashShelfController::CreateInstance() { | |
| 24 DCHECK(!instance_); | |
| 25 instance_ = new ChromeMashShelfController(); | |
| 26 instance_->Init(); | |
| 27 return instance_; | |
| 28 } | |
| 29 | |
| 30 ChromeMashShelfController::ChromeMashShelfController() | |
| 31 : observer_binding_(this), item_delegate_binding_(this) {} | |
| 32 | |
| 33 void ChromeMashShelfController::Init() { | |
| 34 mojo::Connector* connector = | |
| 35 content::MojoShellConnection::Get()->GetConnector(); | |
| 36 connector->ConnectToInterface("mojo:ash_sysui", &shelf_); | |
| 37 | |
| 38 // Set shelf alignment and auto-hide behavior from preferences. | |
| 39 Profile* profile = ProfileManager::GetActiveUserProfile(); | |
| 40 | |
| 41 const std::string& alignment_value = | |
| 42 profile->GetPrefs()->GetString(prefs::kShelfAlignmentLocal); | |
| 43 shelf_->SetAlignment(static_cast<mash::shelf::mojom::Alignment>( | |
| 44 ash::AlignmentFromPref(alignment_value))); | |
| 45 | |
| 46 const std::string& auto_hide_value = | |
| 47 profile->GetPrefs()->GetString(prefs::kShelfAutoHideBehaviorLocal); | |
| 48 shelf_->SetAutoHideBehavior(static_cast<mash::shelf::mojom::AutoHideBehavior>( | |
| 49 ash::AutoHideBehaviorFromPref(auto_hide_value))); | |
| 50 | |
| 51 // Create a test shortcut item to a fake application. | |
| 52 mash::shelf::mojom::ShelfItemPtr item(mash::shelf::mojom::ShelfItem::New()); | |
| 53 item->id = "mojo:fake_app"; | |
| 54 item->title = "Fake Mojo App (test pinned shelf item)"; | |
| 55 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
| 56 const gfx::Image& image = rb.GetImageNamed(IDR_PRODUCT_LOGO_32); | |
| 57 item->image = skia::mojom::Bitmap::From(*image.ToSkBitmap()); | |
| 58 shelf_->AddItem(std::move(item), | |
| 59 item_delegate_binding_.CreateInterfacePtrAndBind()); | |
| 60 | |
| 61 // Start observing the shelf now that it has been initialized. | |
| 62 shelf_->AddObserver(observer_binding_.CreateInterfacePtrAndBind()); | |
| 63 } | |
| 64 | |
| 65 void ChromeMashShelfController::OnAlignmentChanged( | |
| 66 mash::shelf::mojom::Alignment alignment) { | |
| 67 const char* value = | |
| 68 ash::AlignmentToPref(static_cast<ash::ShelfAlignment>(alignment)); | |
| 69 Profile* profile = ProfileManager::GetActiveUserProfile(); | |
| 70 profile->GetPrefs()->SetString(prefs::kShelfAlignmentLocal, value); | |
| 71 } | |
| 72 | |
| 73 void ChromeMashShelfController::OnAutoHideBehaviorChanged( | |
| 74 mash::shelf::mojom::AutoHideBehavior auto_hide) { | |
| 75 const char* value = ash::AutoHideBehaviorToPref( | |
| 76 static_cast<ash::ShelfAutoHideBehavior>(auto_hide)); | |
| 77 if (!value) | |
| 78 return; | |
| 79 Profile* profile = ProfileManager::GetActiveUserProfile(); | |
| 80 profile->GetPrefs()->SetString(prefs::kShelfAutoHideBehaviorLocal, value); | |
| 81 } | |
| 82 | |
| 83 void ChromeMashShelfController::ExecuteCommand(const mojo::String& id, | |
| 84 uint32_t command_id, | |
| 85 int32_t event_flags) { | |
| 86 NOTIMPLEMENTED(); | |
| 87 } | |
| 88 | |
| 89 void ChromeMashShelfController::ItemRemoved(const mojo::String& id) { | |
| 90 NOTIMPLEMENTED(); | |
| 91 } | |
| 92 | |
| 93 void ChromeMashShelfController::ItemReordered(const mojo::String& id, | |
| 94 uint32_t order) { | |
| 95 NOTIMPLEMENTED(); | |
| 96 } | |
| OLD | NEW |