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

Unified Diff: sdk/lib/_internal/pub/lib/src/system_cache.dart

Issue 243683002: Refactor Source. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise all the things. Created 6 years, 8 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
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/source_registry.dart ('k') | sdk/lib/_internal/pub/test/lock_file_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/pub/lib/src/system_cache.dart
diff --git a/sdk/lib/_internal/pub/lib/src/system_cache.dart b/sdk/lib/_internal/pub/lib/src/system_cache.dart
index 9cfca43046c3c820b8b6f75b105a8f162e1e4711..4c48fbad859612912fca43d9125b477a4f2cbb4d 100644
--- a/sdk/lib/_internal/pub/lib/src/system_cache.dart
+++ b/sdk/lib/_internal/pub/lib/src/system_cache.dart
@@ -12,6 +12,7 @@ import 'io.dart';
import 'io.dart' as io show createTempDir;
import 'log.dart' as log;
import 'package.dart';
+import 'source/cached.dart';
import 'source/git.dart';
import 'source/hosted.dart';
import 'source/path.dart';
@@ -29,17 +30,12 @@ class SystemCache {
String get tempDir => path.join(rootDir, '_temp');
- /// Packages which are currently being asynchronously downloaded to the cache.
- final Map<PackageId, Future<Package>> _pendingDownloads;
-
/// The sources from which to get packages.
- final SourceRegistry sources;
+ final sources = new SourceRegistry();
/// Creates a new package cache which is backed by the given directory on the
/// user's file system.
- SystemCache(this.rootDir)
- : _pendingDownloads = new Map<PackageId, Future<Package>>(),
- sources = new SourceRegistry();
+ SystemCache(this.rootDir);
/// Creates a system cache and registers the standard set of sources. If
/// [isOffline] is `true`, then the offline hosted source will be used.
@@ -70,40 +66,13 @@ class SystemCache {
Future<bool> contains(PackageId id) {
var source = sources[id.source];
- if (!source.shouldCache) {
+ if (source is! CachedSource) {
throw new ArgumentError("Package $id is not cacheable.");
}
return source.isInSystemCache(id);
}
- /// Ensures that the package identified by [id] is downloaded to the cache,
- /// loads it, and returns it.
- ///
- /// It is an error to try downloading a package from a source with
- /// `shouldCache == false`.
- ///
- /// If [force] is `true`, then the package is downloaded even if it already
- /// exists in the cache. The previous one will be deleted.
- Future<Package> download(PackageId id, {bool force}) {
- var source = sources[id.source];
-
- if (!source.shouldCache) {
- throw new ArgumentError("Package $id is not cacheable.");
- }
-
- var pending = _pendingDownloads[id];
- if (pending != null) return pending;
-
- var future = source.downloadToSystemCache(id, force: force)
- .whenComplete(() {
- _pendingDownloads.remove(id);
- });
-
- _pendingDownloads[id] = future;
- return future;
- }
-
/// Create a new temporary directory within the system cache. The system
/// cache maintains its own temporary directory that it uses to stage
/// packages into while downloading. It uses this instead of the OS's system
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/source_registry.dart ('k') | sdk/lib/_internal/pub/test/lock_file_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698