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

Side by Side Diff: chrome/browser/ui/webui/ntp/app_launcher_handler.cc

Issue 10920017: [Sync] Generalize StringOrdinal to handle ordinal_in_parent field (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Relax tests Created 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/webui/ntp/app_launcher_handler.h ('k') | chrome/chrome_common.gypi » ('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/ui/webui/ntp/app_launcher_handler.h" 5 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 if (extension->HasAPIPermission( 158 if (extension->HasAPIPermission(
159 extensions::APIPermission::kAppNotifications)) { 159 extensions::APIPermission::kAppNotifications)) {
160 value->SetBoolean("notifications_disabled", 160 value->SetBoolean("notifications_disabled",
161 prefs->IsAppNotificationDisabled(extension->id())); 161 prefs->IsAppNotificationDisabled(extension->id()));
162 } 162 }
163 163
164 if (notification) 164 if (notification)
165 value->Set("notification", SerializeNotification(*notification)); 165 value->Set("notification", SerializeNotification(*notification));
166 166
167 ExtensionSorting* sorting = prefs->extension_sorting(); 167 ExtensionSorting* sorting = prefs->extension_sorting();
168 StringOrdinal page_ordinal = sorting->GetPageOrdinal(extension->id()); 168 syncer::StringOrdinal page_ordinal = sorting->GetPageOrdinal(extension->id());
169 if (!page_ordinal.IsValid()) { 169 if (!page_ordinal.IsValid()) {
170 // Make sure every app has a page ordinal (some predate the page ordinal). 170 // Make sure every app has a page ordinal (some predate the page ordinal).
171 // The webstore app should be on the first page. 171 // The webstore app should be on the first page.
172 page_ordinal = extension->id() == extension_misc::kWebStoreAppId ? 172 page_ordinal = extension->id() == extension_misc::kWebStoreAppId ?
173 sorting->CreateFirstAppPageOrdinal() : 173 sorting->CreateFirstAppPageOrdinal() :
174 sorting->GetNaturalAppPageOrdinal(); 174 sorting->GetNaturalAppPageOrdinal();
175 sorting->SetPageOrdinal(extension->id(), page_ordinal); 175 sorting->SetPageOrdinal(extension->id(), page_ordinal);
176 } 176 }
177 value->SetInteger("page_index", 177 value->SetInteger("page_index",
178 sorting->PageStringOrdinalAsInteger(page_ordinal)); 178 sorting->PageStringOrdinalAsInteger(page_ordinal));
179 179
180 StringOrdinal app_launch_ordinal = 180 syncer::StringOrdinal app_launch_ordinal =
181 sorting->GetAppLaunchOrdinal(extension->id()); 181 sorting->GetAppLaunchOrdinal(extension->id());
182 if (!app_launch_ordinal.IsValid()) { 182 if (!app_launch_ordinal.IsValid()) {
183 // Make sure every app has a launch ordinal (some predate the launch 183 // Make sure every app has a launch ordinal (some predate the launch
184 // ordinal). The webstore's app launch ordinal is always set to the first 184 // ordinal). The webstore's app launch ordinal is always set to the first
185 // position. 185 // position.
186 app_launch_ordinal = extension->id() == extension_misc::kWebStoreAppId ? 186 app_launch_ordinal = extension->id() == extension_misc::kWebStoreAppId ?
187 sorting->CreateFirstAppLaunchOrdinal(page_ordinal) : 187 sorting->CreateFirstAppLaunchOrdinal(page_ordinal) :
188 sorting->CreateNextAppLaunchOrdinal(page_ordinal); 188 sorting->CreateNextAppLaunchOrdinal(page_ordinal);
189 sorting->SetAppLaunchOrdinal(extension->id(), app_launch_ordinal); 189 sorting->SetAppLaunchOrdinal(extension->id(), app_launch_ordinal);
190 } 190 }
191 value->SetString("app_launch_ordinal", app_launch_ordinal.ToString()); 191 value->SetString("app_launch_ordinal", app_launch_ordinal.ToInternalValue());
192 } 192 }
193 193
194 void AppLauncherHandler::RegisterMessages() { 194 void AppLauncherHandler::RegisterMessages() {
195 registrar_.Add(this, chrome::NOTIFICATION_APP_INSTALLED_TO_NTP, 195 registrar_.Add(this, chrome::NOTIFICATION_APP_INSTALLED_TO_NTP,
196 content::Source<WebContents>(web_ui()->GetWebContents())); 196 content::Source<WebContents>(web_ui()->GetWebContents()));
197 197
198 web_ui()->RegisterMessageCallback("getApps", 198 web_ui()->RegisterMessageCallback("getApps",
199 base::Bind(&AppLauncherHandler::HandleGetApps, 199 base::Bind(&AppLauncherHandler::HandleGetApps,
200 base::Unretained(this))); 200 base::Unretained(this)));
201 web_ui()->RegisterMessageCallback("launchApp", 201 web_ui()->RegisterMessageCallback("launchApp",
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 } 645 }
646 646
647 void AppLauncherHandler::HandleSetPageIndex(const ListValue* args) { 647 void AppLauncherHandler::HandleSetPageIndex(const ListValue* args) {
648 ExtensionSorting* extension_sorting = 648 ExtensionSorting* extension_sorting =
649 extension_service_->extension_prefs()->extension_sorting(); 649 extension_service_->extension_prefs()->extension_sorting();
650 650
651 std::string extension_id; 651 std::string extension_id;
652 double page_index; 652 double page_index;
653 CHECK(args->GetString(0, &extension_id)); 653 CHECK(args->GetString(0, &extension_id));
654 CHECK(args->GetDouble(1, &page_index)); 654 CHECK(args->GetDouble(1, &page_index));
655 const StringOrdinal& page_ordinal = 655 const syncer::StringOrdinal& page_ordinal =
656 extension_sorting->PageIntegerAsStringOrdinal( 656 extension_sorting->PageIntegerAsStringOrdinal(
657 static_cast<size_t>(page_index)); 657 static_cast<size_t>(page_index));
658 658
659 // Don't update the page; it already knows the apps have been reordered. 659 // Don't update the page; it already knows the apps have been reordered.
660 AutoReset<bool> auto_reset(&ignore_changes_, true); 660 AutoReset<bool> auto_reset(&ignore_changes_, true);
661 extension_sorting->SetPageOrdinal(extension_id, page_ordinal); 661 extension_sorting->SetPageOrdinal(extension_id, page_ordinal);
662 } 662 }
663 663
664 void AppLauncherHandler::HandleSaveAppPageName(const ListValue* args) { 664 void AppLauncherHandler::HandleSaveAppPageName(const ListValue* args) {
665 string16 name; 665 string16 name;
(...skipping 14 matching lines...) Expand all
680 CHECK(args->GetString(0, &url)); 680 CHECK(args->GetString(0, &url));
681 GURL launch_url(url); 681 GURL launch_url(url);
682 682
683 string16 title; 683 string16 title;
684 CHECK(args->GetString(1, &title)); 684 CHECK(args->GetString(1, &title));
685 685
686 double page_index; 686 double page_index;
687 CHECK(args->GetDouble(2, &page_index)); 687 CHECK(args->GetDouble(2, &page_index));
688 ExtensionSorting* extension_sorting = 688 ExtensionSorting* extension_sorting =
689 extension_service_->extension_prefs()->extension_sorting(); 689 extension_service_->extension_prefs()->extension_sorting();
690 const StringOrdinal& page_ordinal = 690 const syncer::StringOrdinal& page_ordinal =
691 extension_sorting->PageIntegerAsStringOrdinal( 691 extension_sorting->PageIntegerAsStringOrdinal(
692 static_cast<size_t>(page_index)); 692 static_cast<size_t>(page_index));
693 693
694 Profile* profile = Profile::FromWebUI(web_ui()); 694 Profile* profile = Profile::FromWebUI(web_ui());
695 FaviconService* favicon_service = 695 FaviconService* favicon_service =
696 FaviconServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); 696 FaviconServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS);
697 if (!favicon_service) { 697 if (!favicon_service) {
698 LOG(ERROR) << "No favicon service"; 698 LOG(ERROR) << "No favicon service";
699 return; 699 return;
700 } 700 }
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 940
941 ExtensionInstallPrompt* AppLauncherHandler::GetExtensionInstallPrompt() { 941 ExtensionInstallPrompt* AppLauncherHandler::GetExtensionInstallPrompt() {
942 if (!extension_install_ui_.get()) { 942 if (!extension_install_ui_.get()) {
943 Browser* browser = browser::FindBrowserWithWebContents( 943 Browser* browser = browser::FindBrowserWithWebContents(
944 web_ui()->GetWebContents()); 944 web_ui()->GetWebContents());
945 extension_install_ui_.reset( 945 extension_install_ui_.reset(
946 chrome::CreateExtensionInstallPromptWithBrowser(browser)); 946 chrome::CreateExtensionInstallPromptWithBrowser(browser));
947 } 947 }
948 return extension_install_ui_.get(); 948 return extension_install_ui_.get();
949 } 949 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/app_launcher_handler.h ('k') | chrome/chrome_common.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698