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

Side by Side Diff: chrome/browser/sync/engine/syncapi.cc

Issue 7049028: [Sync] Speed up Javascript node operations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 7 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/sync/engine/syncapi.h ('k') | chrome/browser/sync/engine/syncapi_unittest.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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/sync/engine/syncapi.h" 5 #include "chrome/browser/sync/engine/syncapi.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <bitset> 8 #include <bitset>
9 #include <iomanip> 9 #include <iomanip>
10 #include <list> 10 #include <list>
(...skipping 1530 matching lines...) Expand 10 before | Expand all | Expand 10 after
1541 // 'using_explicit_passphrase' in the NigoriSpecifics. 1541 // 'using_explicit_passphrase' in the NigoriSpecifics.
1542 // TODO(tim): Bug 62103. Remove this after it has been pushed out to dev 1542 // TODO(tim): Bug 62103. Remove this after it has been pushed out to dev
1543 // channel users. 1543 // channel users.
1544 void SetUsingExplicitPassphrasePrefForMigration( 1544 void SetUsingExplicitPassphrasePrefForMigration(
1545 WriteTransaction* const trans); 1545 WriteTransaction* const trans);
1546 1546
1547 // Checks for server reachabilty and requests a nudge. 1547 // Checks for server reachabilty and requests a nudge.
1548 void OnIPAddressChangedImpl(); 1548 void OnIPAddressChangedImpl();
1549 1549
1550 // Functions called by ProcessMessage(). 1550 // Functions called by ProcessMessage().
1551 browser_sync::JsArgList ProcessGetNodeByIdMessage( 1551 browser_sync::JsArgList ProcessGetNodesByIdMessage(
1552 const browser_sync::JsArgList& args);
1553
1554 browser_sync::JsArgList ProcessGetChildNodeIdsMessage(
1552 const browser_sync::JsArgList& args); 1555 const browser_sync::JsArgList& args);
1553 1556
1554 browser_sync::JsArgList ProcessFindNodesContainingString( 1557 browser_sync::JsArgList ProcessFindNodesContainingString(
1555 const browser_sync::JsArgList& args); 1558 const browser_sync::JsArgList& args);
1556 1559
1557 // We couple the DirectoryManager and username together in a UserShare member 1560 // We couple the DirectoryManager and username together in a UserShare member
1558 // so we can return a handle to share_ to clients of the API for use when 1561 // so we can return a handle to share_ to clients of the API for use when
1559 // constructing any transaction type. 1562 // constructing any transaction type.
1560 UserShare share_; 1563 UserShare share_;
1561 1564
(...skipping 1143 matching lines...) Expand 10 before | Expand all | Expand 10 after
2705 LogNoRouter(name, args); 2708 LogNoRouter(name, args);
2706 return; 2709 return;
2707 } 2710 }
2708 ReadTransaction trans(GetUserShare()); 2711 ReadTransaction trans(GetUserShare());
2709 ReadNode root(&trans); 2712 ReadNode root(&trans);
2710 root.InitByRootLookup(); 2713 root.InitByRootLookup();
2711 ListValue return_args; 2714 ListValue return_args;
2712 return_args.Append(root.ToValue()); 2715 return_args.Append(root.ToValue());
2713 parent_router_->RouteJsMessageReply( 2716 parent_router_->RouteJsMessageReply(
2714 name, browser_sync::JsArgList(&return_args), sender); 2717 name, browser_sync::JsArgList(&return_args), sender);
2715 } else if (name == "getNodeById") { 2718 } else if (name == "getNodesById") {
2716 if (!parent_router_) { 2719 if (!parent_router_) {
2717 LogNoRouter(name, args); 2720 LogNoRouter(name, args);
2718 return; 2721 return;
2719 } 2722 }
2720 parent_router_->RouteJsMessageReply( 2723 parent_router_->RouteJsMessageReply(
2721 name, ProcessGetNodeByIdMessage(args), sender); 2724 name, ProcessGetNodesByIdMessage(args), sender);
2725 } else if (name == "getChildNodeIds") {
2726 if (!parent_router_) {
2727 LogNoRouter(name, args);
2728 return;
2729 }
2730 parent_router_->RouteJsMessageReply(
2731 name, ProcessGetChildNodeIdsMessage(args), sender);
2722 } else if (name == "findNodesContainingString") { 2732 } else if (name == "findNodesContainingString") {
2723 if (!parent_router_) { 2733 if (!parent_router_) {
2724 LogNoRouter(name, args); 2734 LogNoRouter(name, args);
2725 return; 2735 return;
2726 } 2736 }
2727 parent_router_->RouteJsMessageReply( 2737 parent_router_->RouteJsMessageReply(
2728 name, ProcessFindNodesContainingString(args), sender); 2738 name, ProcessFindNodesContainingString(args), sender);
2729 } else { 2739 } else {
2730 VLOG(1) << "Dropping unknown message " << name 2740 VLOG(1) << "Dropping unknown message " << name
2731 << " with args " << args.ToString(); 2741 << " with args " << args.ToString();
(...skipping 12 matching lines...) Expand all
2744 void SyncManager::SyncInternal::RouteJsMessageReply( 2754 void SyncManager::SyncInternal::RouteJsMessageReply(
2745 const std::string& name, 2755 const std::string& name,
2746 const browser_sync::JsArgList& args, 2756 const browser_sync::JsArgList& args,
2747 const browser_sync::JsEventHandler* target) { 2757 const browser_sync::JsEventHandler* target) {
2748 if (!parent_router_) { 2758 if (!parent_router_) {
2749 return; 2759 return;
2750 } 2760 }
2751 parent_router_->RouteJsMessageReply(name, args, target); 2761 parent_router_->RouteJsMessageReply(name, args, target);
2752 } 2762 }
2753 2763
2754 browser_sync::JsArgList SyncManager::SyncInternal::ProcessGetNodeByIdMessage( 2764 namespace {
2765
2766 bool GetId(const ListValue& ids, int i, int64* id) {
2767 std::string id_str;
2768 if (!ids.GetString(i, &id_str)) {
2769 return false;
2770 }
2771 if (!base::StringToInt64(id_str, id)) {
2772 return false;
2773 }
2774 if (*id == kInvalidId) {
2775 return false;
2776 }
2777 return true;
2778 }
2779
2780 } // namespace
2781
2782 browser_sync::JsArgList SyncManager::SyncInternal::ProcessGetNodesByIdMessage(
2755 const browser_sync::JsArgList& args) { 2783 const browser_sync::JsArgList& args) {
2756 ListValue null_return_args_list; 2784 ListValue return_args;
2757 null_return_args_list.Append(Value::CreateNullValue()); 2785 ListValue* nodes = new ListValue();
2758 browser_sync::JsArgList null_return_args(&null_return_args_list); 2786 return_args.Append(nodes);
2759 std::string id_str; 2787 ListValue* id_list = NULL;
2760 if (!args.Get().GetString(0, &id_str)) { 2788 ReadTransaction trans(GetUserShare());
2761 return null_return_args; 2789 if (args.Get().GetList(0, &id_list)) {
2790 for (size_t i = 0; i < id_list->GetSize(); ++i) {
2791 int64 id = kInvalidId;
2792 if (!GetId(*id_list, i, &id)) {
2793 continue;
2794 }
2795 ReadNode node(&trans);
2796 if (!node.InitByIdLookup(id)) {
2797 continue;
2798 }
2799 nodes->Append(node.ToValue());
2800 }
2762 } 2801 }
2763 int64 id;
2764 if (!base::StringToInt64(id_str, &id)) {
2765 return null_return_args;
2766 }
2767 if (id == kInvalidId) {
2768 return null_return_args;
2769 }
2770 ReadTransaction trans(GetUserShare());
2771 ReadNode node(&trans);
2772 if (!node.InitByIdLookup(id)) {
2773 return null_return_args;
2774 }
2775 ListValue return_args;
2776 return_args.Append(node.ToValue());
2777 return browser_sync::JsArgList(&return_args); 2802 return browser_sync::JsArgList(&return_args);
2778 } 2803 }
2779 2804
2805 browser_sync::JsArgList SyncManager::SyncInternal::
2806 ProcessGetChildNodeIdsMessage(
2807 const browser_sync::JsArgList& args) {
2808 ListValue return_args;
2809 ListValue* child_ids = new ListValue();
2810 return_args.Append(child_ids);
2811 int64 id = kInvalidId;
2812 if (GetId(args.Get(), 0, &id)) {
2813 ReadTransaction trans(GetUserShare());
2814 ReadNode node(&trans);
2815 if (node.InitByIdLookup(id)) {
2816 int64 child_id = node.GetFirstChildId();
2817 while (child_id != kInvalidId) {
2818 ReadNode child_node(&trans);
2819 if (!child_node.InitByIdLookup(child_id)) {
2820 break;
2821 }
2822 child_ids->Append(Value::CreateStringValue(
2823 base::Int64ToString(child_id)));
2824 child_id = child_node.GetSuccessorId();
2825 }
2826 }
2827 }
2828 return browser_sync::JsArgList(&return_args);
2829 }
2830
2780 browser_sync::JsArgList SyncManager::SyncInternal:: 2831 browser_sync::JsArgList SyncManager::SyncInternal::
2781 ProcessFindNodesContainingString( 2832 ProcessFindNodesContainingString(
2782 const browser_sync::JsArgList& args) { 2833 const browser_sync::JsArgList& args) {
2783 std::string query; 2834 std::string query;
2784 ListValue return_args; 2835 ListValue return_args;
2785 if (!args.Get().GetString(0, &query)) { 2836 if (!args.Get().GetString(0, &query)) {
2786 return_args.Append(new ListValue()); 2837 return_args.Append(new ListValue());
2787 return browser_sync::JsArgList(&return_args); 2838 return browser_sync::JsArgList(&return_args);
2788 } 2839 }
2789 2840
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
2951 void SyncManager::TriggerOnIncomingNotificationForTest( 3002 void SyncManager::TriggerOnIncomingNotificationForTest(
2952 const syncable::ModelTypeBitSet& model_types) { 3003 const syncable::ModelTypeBitSet& model_types) {
2953 syncable::ModelTypePayloadMap model_types_with_payloads = 3004 syncable::ModelTypePayloadMap model_types_with_payloads =
2954 syncable::ModelTypePayloadMapFromBitSet(model_types, 3005 syncable::ModelTypePayloadMapFromBitSet(model_types,
2955 std::string()); 3006 std::string());
2956 3007
2957 data_->OnIncomingNotification(model_types_with_payloads); 3008 data_->OnIncomingNotification(model_types_with_payloads);
2958 } 3009 }
2959 3010
2960 } // namespace sync_api 3011 } // namespace sync_api
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/syncapi.h ('k') | chrome/browser/sync/engine/syncapi_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698