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

Side by Side Diff: chrome/common/extensions/api/extension_api.cc

Issue 11571014: Lazy load chrome.* APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix interactive_ui_tests Created 7 years, 10 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
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/common/extensions/api/extension_api.h" 5 #include "chrome/common/extensions/api/extension_api.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 if (!IsFeatureAllowedForExtension(*i, extension)) { 536 if (!IsFeatureAllowedForExtension(*i, extension)) {
537 apis->erase(i++); 537 apis->erase(i++);
538 } else { 538 } else {
539 ++i; 539 ++i;
540 } 540 }
541 } 541 }
542 } 542 }
543 543
544 } // namespace 544 } // namespace
545 545
546 scoped_ptr<std::set<std::string> > ExtensionAPI::GetAPIsForContext( 546 std::set<std::string> ExtensionAPI::GetAPIsForContext(
547 Feature::Context context, const Extension* extension, const GURL& url) { 547 Feature::Context context, const Extension* extension, const GURL& url) {
548 // We're forced to load all schemas now because we need to know the metadata 548 // We're forced to load all schemas now because we need to know the metadata
549 // about every API -- and the metadata is stored in the schemas themselves. 549 // about every API -- and the metadata is stored in the schemas themselves.
550 // This is a shame. 550 // This is a shame.
551 // TODO(aa/kalman): store metadata in a separate file and don't load all 551 // TODO(aa/kalman): store metadata in a separate file and don't load all
552 // schemas. 552 // schemas.
553 LoadAllSchemas(); 553 LoadAllSchemas();
554 554
555 std::set<std::string> temp_result; 555 std::set<std::string> temp_result;
556 556
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 case Feature::WEB_PAGE_CONTEXT: 594 case Feature::WEB_PAGE_CONTEXT:
595 if (url.is_valid()) { 595 if (url.is_valid()) {
596 // Availablility is determined by the url. 596 // Availablility is determined by the url.
597 GetAPIsMatchingURL(url, &temp_result); 597 GetAPIsMatchingURL(url, &temp_result);
598 } 598 }
599 break; 599 break;
600 } 600 }
601 601
602 // Filter out all non-API features and remove the feature type part of the 602 // Filter out all non-API features and remove the feature type part of the
603 // name. 603 // name.
604 scoped_ptr<std::set<std::string> > result(new std::set<std::string>()); 604 std::set<std::string> result;
605 for (std::set<std::string>::iterator iter = temp_result.begin(); 605 for (std::set<std::string>::iterator iter = temp_result.begin();
606 iter != temp_result.end(); ++iter) { 606 iter != temp_result.end(); ++iter) {
607 std::string feature_type; 607 std::string feature_type;
608 std::string feature_name; 608 std::string feature_name;
609 SplitDependencyName(*iter, &feature_type, &feature_name); 609 SplitDependencyName(*iter, &feature_type, &feature_name);
610 if (feature_type == "api") 610 if (feature_type == "api")
611 result->insert(feature_name); 611 result.insert(feature_name);
612 } 612 }
613 613
614 return result.Pass(); 614 return result;
615 }
616
617 std::set<std::string> ExtensionAPI::GetAllAPINames() {
618 std::set<std::string> result;
619 for (SchemaMap::iterator i = schemas_.begin(); i != schemas_.end(); ++i)
620 result.insert(i->first);
621 for (UnloadedSchemaMap::iterator i = unloaded_schemas_.begin();
622 i != unloaded_schemas_.end(); ++i) {
623 result.insert(i->first);
624 }
625 return result;
615 } 626 }
616 627
617 Feature* ExtensionAPI::GetFeature(const std::string& full_name) { 628 Feature* ExtensionAPI::GetFeature(const std::string& full_name) {
618 // Ensure it's loaded. 629 // Ensure it's loaded.
619 GetSchema(full_name); 630 GetSchema(full_name);
620 631
621 std::string child_name; 632 std::string child_name;
622 std::string api_namespace = GetAPINameFromFullName(full_name, &child_name); 633 std::string api_namespace = GetAPINameFromFullName(full_name, &child_name);
623 634
624 APIFeatureMap::iterator feature_map = features_.find(api_namespace); 635 APIFeatureMap::iterator feature_map = features_.find(api_namespace);
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 788
778 void ExtensionAPI::LoadAllSchemas() { 789 void ExtensionAPI::LoadAllSchemas() {
779 while (unloaded_schemas_.size()) { 790 while (unloaded_schemas_.size()) {
780 std::map<std::string, base::StringPiece>::iterator it = 791 std::map<std::string, base::StringPiece>::iterator it =
781 unloaded_schemas_.begin(); 792 unloaded_schemas_.begin();
782 LoadSchema(it->first, it->second); 793 LoadSchema(it->first, it->second);
783 } 794 }
784 } 795 }
785 796
786 } // namespace extensions 797 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698