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

Unified Diff: utils/pub/source.dart

Issue 10749014: Refactor Source to take the system cache as a parameter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merge Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: utils/pub/source.dart
diff --git a/utils/pub/source.dart b/utils/pub/source.dart
index 4e7db4980cd25e7d894d236b423e8fad1b997ad5..21144ce3ea8c56405cce0d50bc4db5993d20c866 100644
--- a/utils/pub/source.dart
+++ b/utils/pub/source.dart
@@ -4,8 +4,10 @@
#library('source');
+#import('io.dart');
#import('package.dart');
#import('pubspec.dart');
+#import('system_cache.dart');
#import('version.dart');
/**
@@ -32,6 +34,37 @@ class Source {
abstract bool get shouldCache();
/**
+ * The system cache with which this source is registered.
+ */
+ SystemCache get systemCache() {
+ assert(_systemCache != null);
+ return _systemCache;
+ }
+
+ /**
+ * The system cache variable. Set by [_bind].
+ */
+ SystemCache _systemCache;
+
+ /**
+ * The root directory of this source's cache within the system cache.
+ *
+ * This shouldn't be overridden by subclasses.
+ */
+ String get systemCacheRoot() => join(systemCache.rootDir, name);
+
+ /**
+ * Records the system cache to which this source belongs.
+ *
+ * This should only be called once for each source, by [SystemCache.register].
+ * It should not be overridden by base classes.
+ */
+ void bind(SystemCache systemCache) {
+ assert(_systemCache == null);
+ this._systemCache = systemCache;
+ }
+
+ /**
* Get the list of all versions that exist for the package described by
* [description].
*
@@ -67,13 +100,13 @@ class Source {
/**
* Returns the directory in the system cache that the package identified by
- * [id] should be installed to. [parent] is this source's subdirectory in the
- * system cache directory.
+ * [id] should be installed to. This should return a path to a subdirectory of
+ * [systemCacheRoot].
*
* This doesn't need to be implemented if [shouldCache] is false.
*/
- String systemCacheDirectory(PackageId id, String parent) =>
- join(parent, packageName(id.description));
+ String systemCacheDirectory(PackageId id) =>
+ join(systemCacheRoot, packageName(id.description));
/**
* When a [Pubspec] is parsed, it reads in the description for each

Powered by Google App Engine
This is Rietveld 408576698