| 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/extensions/chrome_app_sorting.h" | 5 #include "chrome/browser/extensions/chrome_app_sorting.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 if (new_app_launch_ordinal.EqualsOrBothInvalid( | 314 if (new_app_launch_ordinal.EqualsOrBothInvalid( |
| 315 GetAppLaunchOrdinal(extension_id))) { | 315 GetAppLaunchOrdinal(extension_id))) { |
| 316 return; | 316 return; |
| 317 } | 317 } |
| 318 | 318 |
| 319 syncer::StringOrdinal page_ordinal = GetPageOrdinal(extension_id); | 319 syncer::StringOrdinal page_ordinal = GetPageOrdinal(extension_id); |
| 320 RemoveOrdinalMapping( | 320 RemoveOrdinalMapping( |
| 321 extension_id, page_ordinal, GetAppLaunchOrdinal(extension_id)); | 321 extension_id, page_ordinal, GetAppLaunchOrdinal(extension_id)); |
| 322 AddOrdinalMapping(extension_id, page_ordinal, new_app_launch_ordinal); | 322 AddOrdinalMapping(extension_id, page_ordinal, new_app_launch_ordinal); |
| 323 | 323 |
| 324 base::Value* new_value = new_app_launch_ordinal.IsValid() ? | 324 base::Value* new_value = |
| 325 new base::StringValue(new_app_launch_ordinal.ToInternalValue()) : | 325 new_app_launch_ordinal.IsValid() |
| 326 NULL; | 326 ? new base::Value(new_app_launch_ordinal.ToInternalValue()) |
| 327 : NULL; |
| 327 | 328 |
| 328 ExtensionPrefs::Get(browser_context_)->UpdateExtensionPref( | 329 ExtensionPrefs::Get(browser_context_)->UpdateExtensionPref( |
| 329 extension_id, | 330 extension_id, |
| 330 kPrefAppLaunchOrdinal, | 331 kPrefAppLaunchOrdinal, |
| 331 new_value); | 332 new_value); |
| 332 SyncIfNeeded(extension_id); | 333 SyncIfNeeded(extension_id); |
| 333 } | 334 } |
| 334 | 335 |
| 335 syncer::StringOrdinal ChromeAppSorting::CreateFirstAppLaunchOrdinal( | 336 syncer::StringOrdinal ChromeAppSorting::CreateFirstAppLaunchOrdinal( |
| 336 const syncer::StringOrdinal& page_ordinal) const { | 337 const syncer::StringOrdinal& page_ordinal) const { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 const syncer::StringOrdinal& new_page_ordinal) { | 394 const syncer::StringOrdinal& new_page_ordinal) { |
| 394 // No work is required if the old and new values are the same. | 395 // No work is required if the old and new values are the same. |
| 395 if (new_page_ordinal.EqualsOrBothInvalid(GetPageOrdinal(extension_id))) | 396 if (new_page_ordinal.EqualsOrBothInvalid(GetPageOrdinal(extension_id))) |
| 396 return; | 397 return; |
| 397 | 398 |
| 398 syncer::StringOrdinal app_launch_ordinal = GetAppLaunchOrdinal(extension_id); | 399 syncer::StringOrdinal app_launch_ordinal = GetAppLaunchOrdinal(extension_id); |
| 399 RemoveOrdinalMapping( | 400 RemoveOrdinalMapping( |
| 400 extension_id, GetPageOrdinal(extension_id), app_launch_ordinal); | 401 extension_id, GetPageOrdinal(extension_id), app_launch_ordinal); |
| 401 AddOrdinalMapping(extension_id, new_page_ordinal, app_launch_ordinal); | 402 AddOrdinalMapping(extension_id, new_page_ordinal, app_launch_ordinal); |
| 402 | 403 |
| 403 base::Value* new_value = new_page_ordinal.IsValid() ? | 404 base::Value* new_value = |
| 404 new base::StringValue(new_page_ordinal.ToInternalValue()) : | 405 new_page_ordinal.IsValid() |
| 405 NULL; | 406 ? new base::Value(new_page_ordinal.ToInternalValue()) |
| 407 : NULL; |
| 406 | 408 |
| 407 ExtensionPrefs::Get(browser_context_)->UpdateExtensionPref( | 409 ExtensionPrefs::Get(browser_context_)->UpdateExtensionPref( |
| 408 extension_id, | 410 extension_id, |
| 409 kPrefPageOrdinal, | 411 kPrefPageOrdinal, |
| 410 new_value); | 412 new_value); |
| 411 SyncIfNeeded(extension_id); | 413 SyncIfNeeded(extension_id); |
| 412 } | 414 } |
| 413 | 415 |
| 414 void ChromeAppSorting::ClearOrdinals(const std::string& extension_id) { | 416 void ChromeAppSorting::ClearOrdinals(const std::string& extension_id) { |
| 415 RemoveOrdinalMapping(extension_id, | 417 RemoveOrdinalMapping(extension_id, |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 for (AppLaunchOrdinalMap::const_iterator it = m.begin(); it != m.end(); | 620 for (AppLaunchOrdinalMap::const_iterator it = m.begin(); it != m.end(); |
| 619 ++it) { | 621 ++it) { |
| 620 const std::string& id = it->second; | 622 const std::string& id = it->second; |
| 621 if (ntp_hidden_extensions_.count(id) == 0) | 623 if (ntp_hidden_extensions_.count(id) == 0) |
| 622 result++; | 624 result++; |
| 623 } | 625 } |
| 624 return result; | 626 return result; |
| 625 } | 627 } |
| 626 | 628 |
| 627 } // namespace extensions | 629 } // namespace extensions |
| OLD | NEW |