Home | History | Annotate | Download | only in mre
      1 <!DOCTYPE html>
      2 <!--
      3 Copyright 2015 The Chromium Authors. All rights reserved.
      4 Use of this source code is governed by a BSD-style license that can be
      5 found in the LICENSE file.
      6 -->
      7 <link rel="import" href="/tracing/base/guid.html">
      8 <link rel="import" href="/tracing/base/xhr.html">
      9 <link rel="import" href="/tracing/base/utils.html">
     10 <link rel="import" href="/tracing/extras/full_config.html">
     11 <link rel="import" href="/tracing/importer/import.html">
     12 <link rel="import" href="/tracing/model/model.html">
     13 
     14 <script>
     15 'use strict';
     16 
     17 tr.exportTo('pi.mre', function() {
     18   function FileHandle(canonicalUrl) {
     19     this.canonicalUrl_ = canonicalUrl;
     20   }
     21 
     22   FileHandle.prototype = {
     23     get canonicalUrl() { return this.canonicalUrl_; },
     24 
     25     asDict: function() {
     26       var d = {
     27         canonical_url: this.canonicalUrl_
     28       };
     29 
     30       this._asDictInto(d);
     31       if (d.type === undefined)
     32         throw new Error('_asDictInto must set type field');
     33     },
     34 
     35     load: function() {
     36       throw new Error('Not implemented');
     37     }
     38   };
     39 
     40   FileHandle.fromDict = function(handleDict) {
     41     if (handleDict.type === 'url')
     42       return URLFileHandle.fromDict(handleDict);
     43 
     44     throw new Error('Not implemented: fromDict for ' + handleDict.type);
     45   };
     46 
     47 
     48   function URLFileHandle(canonicalUrl, urlToLoad) {
     49     // TODO(eakuefner): assert startswith file://
     50     FileHandle.call(this, canonicalUrl);
     51     this.urlToLoad = urlToLoad;
     52   }
     53 
     54   URLFileHandle.prototype = {
     55     __proto__: FileHandle.prototype,
     56 
     57     _asDictInto: function(handleDict) {
     58       handleDict.urlToLoad = this.urlToLoad;
     59       handleDict.type = 'url';
     60     },
     61 
     62     load: function() {
     63       try {
     64         return tr.b.getSync(this.urlToLoad);
     65       } catch (ex) {
     66         var err = new Error('Could not open ' + this.urlToLoad);
     67         err.name = 'FileLoadingError';
     68         throw err;
     69       }
     70     }
     71   };
     72 
     73   URLFileHandle.fromDict = function(handleDict) {
     74     return new URLFileHandle(handleDict.canonical_url, handleDict.url_to_load);
     75   };
     76 
     77   return {
     78     FileHandle: FileHandle,
     79     URLFileHandle: URLFileHandle
     80   };
     81 });
     82 </script>
     83