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

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: comments/TODOs Created 7 years, 11 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 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 if (!IsFeatureAllowedForExtension(*i, extension)) { 576 if (!IsFeatureAllowedForExtension(*i, extension)) {
577 apis->erase(i++); 577 apis->erase(i++);
578 } else { 578 } else {
579 ++i; 579 ++i;
580 } 580 }
581 } 581 }
582 } 582 }
583 583
584 } // namespace 584 } // namespace
585 585
586 scoped_ptr<std::set<std::string> > ExtensionAPI::GetAPIsForContext( 586 std::set<std::string> ExtensionAPI::GetAPIsForContext(
587 Feature::Context context, const Extension* extension, const GURL& url) { 587 Feature::Context context, const Extension* extension, const GURL& url) {
588 // We're forced to load all schemas now because we need to know the metadata 588 // We're forced to load all schemas now because we need to know the metadata
589 // about every API -- and the metadata is stored in the schemas themselves. 589 // about every API -- and the metadata is stored in the schemas themselves.
590 // This is a shame. 590 // This is a shame.
591 // TODO(aa/kalman): store metadata in a separate file and don't load all 591 // TODO(aa/kalman): store metadata in a separate file and don't load all
592 // schemas. 592 // schemas.
593 LoadAllSchemas(); 593 LoadAllSchemas();
594 594
595 std::set<std::string> temp_result; 595 std::set<std::string> temp_result;
596 596
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 case Feature::WEB_PAGE_CONTEXT: 634 case Feature::WEB_PAGE_CONTEXT:
635 if (url.is_valid()) { 635 if (url.is_valid()) {
636 // Availablility is determined by the url. 636 // Availablility is determined by the url.
637 GetAPIsMatchingURL(url, &temp_result); 637 GetAPIsMatchingURL(url, &temp_result);
638 } 638 }
639 break; 639 break;
640 } 640 }
641 641
642 // Filter out all non-API features and remove the feature type part of the 642 // Filter out all non-API features and remove the feature type part of the
643 // name. 643 // name.
644 scoped_ptr<std::set<std::string> > result(new std::set<std::string>()); 644 std::set<std::string> result;
645 for (std::set<std::string>::iterator iter = temp_result.begin(); 645 for (std::set<std::string>::iterator iter = temp_result.begin();
646 iter != temp_result.end(); ++iter) { 646 iter != temp_result.end(); ++iter) {
647 std::string feature_type; 647 std::string feature_type;
648 std::string feature_name; 648 std::string feature_name;
649 SplitDependencyName(*iter, &feature_type, &feature_name); 649 SplitDependencyName(*iter, &feature_type, &feature_name);
650 if (feature_type == "api") 650 if (feature_type == "api")
651 result->insert(feature_name); 651 result.insert(feature_name);
652 } 652 }
653 653
654 return result.Pass(); 654 return result;
655 }
656
657 std::set<std::string> ExtensionAPI::GetAllAPINames() {
658 std::set<std::string> result;
659 for (SchemaMap::iterator i = schemas_.begin(); i != schemas_.end(); ++i)
660 result.insert(i->first);
661 for (UnloadedSchemaMap::iterator i = unloaded_schemas_.begin();
662 i != unloaded_schemas_.end(); ++i) {
663 result.insert(i->first);
664 }
665 return result;
655 } 666 }
656 667
657 Feature* ExtensionAPI::GetFeature(const std::string& full_name) { 668 Feature* ExtensionAPI::GetFeature(const std::string& full_name) {
658 // Ensure it's loaded. 669 // Ensure it's loaded.
659 GetSchema(full_name); 670 GetSchema(full_name);
660 671
661 std::string child_name; 672 std::string child_name;
662 std::string api_namespace = GetAPINameFromFullName(full_name, &child_name); 673 std::string api_namespace = GetAPINameFromFullName(full_name, &child_name);
663 674
664 APIFeatureMap::iterator feature_map = features_.find(api_namespace); 675 APIFeatureMap::iterator feature_map = features_.find(api_namespace);
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 828
818 void ExtensionAPI::LoadAllSchemas() { 829 void ExtensionAPI::LoadAllSchemas() {
819 while (unloaded_schemas_.size()) { 830 while (unloaded_schemas_.size()) {
820 std::map<std::string, base::StringPiece>::iterator it = 831 std::map<std::string, base::StringPiece>::iterator it =
821 unloaded_schemas_.begin(); 832 unloaded_schemas_.begin();
822 LoadSchema(it->first, it->second); 833 LoadSchema(it->first, it->second);
823 } 834 }
824 } 835 }
825 836
826 } // namespace extensions 837 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698